Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: scripts/slave/recipe_modules/json/util.py

Issue 23889036: Refactor the way that TestApi works so that it is actually useful. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: License headers Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « scripts/slave/recipe_modules/json/test_api.py ('k') | scripts/slave/recipe_modules/path/api.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 def convert_trie_to_flat_paths(trie, prefix=None):
2 # Cloned from webkitpy.layout_tests.layout_package.json_results_generator
3 # so that this code can stand alone.
4 result = {}
5 for name, data in trie.iteritems():
6 if prefix:
7 name = prefix + "/" + name
8
9 if len(data) and not "actual" in data and not "expected" in data:
10 result.update(convert_trie_to_flat_paths(data, name))
11 else:
12 result[name] = data
13
14 return result
15
16
17 class TestResults(object):
18 def __init__(self, jsonish=None):
19 self.raw = jsonish or {}
20
21 self.tests = convert_trie_to_flat_paths(self.raw.get('tests', {}))
22 self.passes = {}
23 self.unexpected_passes = {}
24 self.failures = {}
25 self.unexpected_failures = {}
26 self.flakes = {}
27 self.unexpected_flakes = {}
28
29 for (test, result) in self.tests.iteritems():
30 key = 'unexpected_' if result.get('is_unexpected') else ''
31 actual_result = result['actual']
32 data = actual_result
33 if ' PASS' in actual_result:
34 key += 'flakes'
35 elif actual_result == 'PASS':
36 key += 'passes'
37 data = result
38 else:
39 key += 'failures'
40 getattr(self, key)[test] = data
41
42 def __getattr__(self, key):
43 if key in self.raw:
44 return self.raw[key]
45 raise AttributeError("'%s' object has no attribute '%s'" %
46 (self.__class__, key)) # pragma: no cover
47
48 def add_result(self, name, expected, actual=None):
49 """Adds a test result to a 'json test results' compatible object.
50 Args:
51 name - A full test name delimited by '/'. ex. 'some/category/test.html'
52 expected - The string value for the 'expected' result of this test.
53 actual (optional) - If not None, this is the actual result of the test.
54 Otherwise this will be set equal to expected.
55
56 The test will also get an 'is_unexpected' key if actual != expected.
57 """
58 actual = actual or expected
59 entry = self.tests
60 for token in name.split('/'):
61 entry = entry.setdefault(token, {})
62 entry['expected'] = expected
63 entry['actual'] = actual
64 if expected != actual:
65 entry['is_unexpected'] = True
66
67 def as_jsonish(self):
68 ret = self.raw.copy()
69 ret.setdefault('tests', {}).update(self.tests)
70 return ret
71
OLDNEW
« no previous file with comments | « scripts/slave/recipe_modules/json/test_api.py ('k') | scripts/slave/recipe_modules/path/api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698