Commit 2048d869 authored by Juan Antonio Navarro Perez's avatar Juan Antonio Navarro Perez Committed by Commit Bot

[flakiness_cli] Convert builders data to pandas.DataFrame

Add a function to conver the data returned by test-results server about
known masters, builders, and test_types into a DataFrame for more
convenient querying of the data on it.

Also add a corresponding unit test.

NOTRY=true

Bug: 875251
Change-Id: Ifa03250669fe3b661f093ff0e1ca172db85fade6
Reviewed-on: https://chromium-review.googlesource.com/1179888
Commit-Queue: Juan Antonio Navarro Pérez <perezju@chromium.org>
Reviewed-by: default avatarNed Nguyen <nednguyen@google.com>
Cr-Commit-Position: refs/heads/master@{#585004}
parent bf75bad5
...@@ -9,9 +9,13 @@ import argparse ...@@ -9,9 +9,13 @@ import argparse
import sys import sys
from test_results import api from test_results import api
from test_results import frames
def main(): def main():
if frames.pandas is None:
return 'ERROR: This tool requires pandas to run, try: pip install pandas'
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='action') subparsers = parser.add_subparsers(dest='action')
subparsers.required = True subparsers.required = True
...@@ -23,7 +27,8 @@ def main(): ...@@ -23,7 +27,8 @@ def main():
args = parser.parse_args() args = parser.parse_args()
if args.action == 'builders': if args.action == 'builders':
print api.GetBuilders() data = api.GetBuilders()
print frames.BuildersDataFrame(data)
elif args.action == 'results': elif args.action == 'results':
print api.GetTestResults(args.master, args.builder, args.test_type) print api.GetTestResults(args.master, args.builder, args.test_type)
else: else:
......
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Module to convert json responses from test-results into data frames."""
try:
import pandas
except ImportError:
pandas = None
def BuildersDataFrame(data):
def iter_rows():
for master in data['masters']:
for test_type, builders in master['tests'].iteritems():
for builder_name in builders['builders']:
yield master['name'], builder_name, test_type
return pandas.DataFrame.from_records(
iter_rows(), columns=('master', 'builder', 'test_type'))
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import unittest
from test_results import frames
@unittest.skipIf(frames.pandas is None, 'pandas module not available')
class TestDataFrames(unittest.TestCase):
def testBuildersDataFrame(self):
sample_data = {
'masters': [
{
'name': 'chromium.perf',
'tests': {
'all_platforms_test': {
'builders': [
'my-mac-bot',
'my-linux-bot',
'my-android-bot'
]
},
'desktop_test': {
'builders': [
'my-mac-bot',
'my-linux-bot'
]
},
'mobile_test': {
'builders': [
'my-android-bot'
]
}
}
},
{
'name': 'chromium.perf.fyi',
'tests': {
'mobile_test': {
'builders': [
'my-new-android-bot'
]
}
}
}
]
}
df = frames.BuildersDataFrame(sample_data)
# Poke and check a few simple facts about our sample data.
# There are two masters: chromium.perf, chromium.perf.fyi.
self.assertItemsEqual(
df['master'].unique(), ['chromium.perf', 'chromium.perf.fyi'])
# The 'desktop_test' runs on desktop builders only.
self.assertItemsEqual(
df[df['test_type'] == 'desktop_test']['builder'].unique(),
['my-mac-bot', 'my-linux-bot'])
# The 'mobile_test' runs on mobile builders only.
self.assertItemsEqual(
df[df['test_type'] == 'mobile_test']['builder'].unique(),
['my-android-bot', 'my-new-android-bot'])
# The new android bot is on the chromium.perf.fyi waterfall.
self.assertItemsEqual(
df[df['builder'] == 'my-new-android-bot']['master'].unique(),
['chromium.perf.fyi'])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment