OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import functools | 5 import functools |
6 import json | 6 import json |
7 import os | 7 import os |
8 import tempfile | 8 import tempfile |
9 | 9 |
10 from cStringIO import StringIO | 10 from cStringIO import StringIO |
11 | 11 |
12 from slave import recipe_api | 12 from slave import recipe_api |
13 | 13 |
| 14 from .util import TestResults |
| 15 |
14 class StringListIO(object): | 16 class StringListIO(object): |
15 def __init__(self): | 17 def __init__(self): |
16 self.lines = [StringIO()] | 18 self.lines = [StringIO()] |
17 | 19 |
18 def write(self, s): | 20 def write(self, s): |
19 while s: | 21 while s: |
20 i = s.find('\n') | 22 i = s.find('\n') |
21 if i == -1: | 23 if i == -1: |
22 self.lines[-1].write(s) | 24 self.lines[-1].write(s) |
23 break | 25 break |
24 self.lines[-1].write(s[:i]) | 26 self.lines[-1].write(s[:i]) |
25 self.lines[-1] = self.lines[-1].getvalue() | 27 self.lines[-1] = self.lines[-1].getvalue() |
26 self.lines.append(StringIO()) | 28 self.lines.append(StringIO()) |
27 s = s[i+1:] | 29 s = s[i+1:] |
28 | 30 |
29 def close(self): | 31 def close(self): |
30 if not isinstance(self.lines[-1], basestring): | 32 if not isinstance(self.lines[-1], basestring): |
31 self.lines[-1] = self.lines[-1].getvalue() | 33 self.lines[-1] = self.lines[-1].getvalue() |
32 | 34 |
33 | 35 |
34 def convert_trie_to_flat_paths(trie, prefix=None): | |
35 # Cloned from webkitpy.layout_tests.layout_package.json_results_generator | |
36 # so that this code can stand alone. | |
37 result = {} | |
38 for name, data in trie.iteritems(): | |
39 if prefix: | |
40 name = prefix + "/" + name | |
41 | |
42 if len(data) and not "actual" in data and not "expected" in data: | |
43 result.update(convert_trie_to_flat_paths(data, name)) | |
44 else: | |
45 result[name] = data | |
46 | |
47 return result | |
48 | |
49 | |
50 class TestResults(object): | |
51 def __init__(self, jsonish): | |
52 self.raw = jsonish | |
53 | |
54 self.tests = convert_trie_to_flat_paths(jsonish.get('tests', {})) | |
55 self.passes = {} | |
56 self.unexpected_passes = {} | |
57 self.failures = {} | |
58 self.unexpected_failures = {} | |
59 self.flakes = {} | |
60 self.unexpected_flakes = {} | |
61 | |
62 for (test, result) in self.tests.iteritems(): | |
63 key = 'unexpected_' if result.get('is_unexpected') else '' | |
64 actual_result = result['actual'] | |
65 data = actual_result | |
66 if ' PASS' in actual_result: | |
67 key += 'flakes' | |
68 elif actual_result == 'PASS': | |
69 key += 'passes' | |
70 data = result | |
71 else: | |
72 key += 'failures' | |
73 getattr(self, key)[test] = data | |
74 | |
75 def __getattr__(self, key): | |
76 if key in self.raw: | |
77 return self.raw[key] | |
78 raise AttributeError("'%s' object has no attribute '%s'" % | |
79 (self.__class__, key)) # pragma: no cover | |
80 | |
81 | |
82 class JsonOutputPlaceholder(recipe_api.Placeholder): | 36 class JsonOutputPlaceholder(recipe_api.Placeholder): |
83 """JsonOutputPlaceholder is meant to be a placeholder object which, when added | 37 """JsonOutputPlaceholder is meant to be a placeholder object which, when added |
84 to a step's cmd list, will be replaced by annotated_run with the command | 38 to a step's cmd list, will be replaced by annotated_run with the command |
85 parameters --output-json /path/to/file during the evaluation of your recipe | 39 parameters --output-json /path/to/file during the evaluation of your recipe |
86 generator. | 40 generator. |
87 | 41 |
88 This placeholder can be optionally added when you use the Steps.step() | 42 This placeholder can be optionally added when you use the Steps.step() |
89 method in this module. | 43 method in this module. |
90 | 44 |
91 After the termination of the step, this file is expected to contain a valid | 45 After the termination of the step, this file is expected to contain a valid |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 135 |
182 It's vastly preferable to have your recipe only pass the bare minimum | 136 It's vastly preferable to have your recipe only pass the bare minimum |
183 of arguments to steps. Passing property objects obscures the data that | 137 of arguments to steps. Passing property objects obscures the data that |
184 the script actually consumes from the property object. | 138 the script actually consumes from the property object. |
185 """ | 139 """ |
186 prop_str = self.dumps(dict(self.m.properties)) | 140 prop_str = self.dumps(dict(self.m.properties)) |
187 return [ | 141 return [ |
188 '--factory-properties', prop_str, | 142 '--factory-properties', prop_str, |
189 '--build-properties', prop_str | 143 '--build-properties', prop_str |
190 ] | 144 ] |
191 | |
OLD | NEW |