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

Side by Side Diff: typ/json_results.py

Issue 2693503003: Add test times to the JSON results. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | typ/tests/json_results_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 Google Inc. All rights reserved. 1 # Copyright 2014 Google Inc. All rights reserved.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 skipped_tests = set(all_test_names) - passing_tests - failed_tests 83 skipped_tests = set(all_test_names) - passing_tests - failed_tests
84 84
85 full_results['num_failures_by_type'] = OrderedDict() 85 full_results['num_failures_by_type'] = OrderedDict()
86 full_results['num_failures_by_type']['FAIL'] = len(failed_tests) 86 full_results['num_failures_by_type']['FAIL'] = len(failed_tests)
87 full_results['num_failures_by_type']['PASS'] = len(passing_tests) 87 full_results['num_failures_by_type']['PASS'] = len(passing_tests)
88 full_results['num_failures_by_type']['SKIP'] = len(skipped_tests) 88 full_results['num_failures_by_type']['SKIP'] = len(skipped_tests)
89 89
90 full_results['tests'] = OrderedDict() 90 full_results['tests'] = OrderedDict()
91 91
92 for test_name in all_test_names: 92 for test_name in all_test_names:
93 value = OrderedDict() 93 value = _results_for_test(test_name, results)
94 value['actual'] = _actual_results_for_test(test_name, results)
95 if test_name in skipped_tests: 94 if test_name in skipped_tests:
96 value['expected'] = 'SKIP' 95 value['expected'] = 'SKIP'
97 else: 96 else:
98 value['expected'] = 'PASS' 97 value['expected'] = 'PASS'
99 if value['actual'].endswith('FAIL'): 98 if value['actual'].endswith('FAIL'):
100 value['is_unexpected'] = True 99 value['is_unexpected'] = True
101 _add_path_to_trie(full_results['tests'], test_name, value) 100 _add_path_to_trie(full_results['tests'], test_name, value)
102 101
103 return full_results 102 return full_results
104 103
(...skipping 29 matching lines...) Expand all
134 # failed, but that's at least consistent with a test that is 133 # failed, but that's at least consistent with a test that is
135 # skipped every time. 134 # skipped every time.
136 names.remove(r.name) 135 names.remove(r.name)
137 return names 136 return names
138 137
139 138
140 def _passing_test_names(results): 139 def _passing_test_names(results):
141 return set(r.name for r in results.results if r.actual == ResultType.Pass) 140 return set(r.name for r in results.results if r.actual == ResultType.Pass)
142 141
143 142
144 def _actual_results_for_test(test_name, results): 143 def _results_for_test(test_name, results):
144 value = OrderedDict()
145 actuals = [] 145 actuals = []
146 times = []
146 for r in results.results: 147 for r in results.results:
147 if r.name == test_name: 148 if r.name == test_name:
148 if r.actual == ResultType.Failure: 149 if r.actual == ResultType.Failure:
149 actuals.append('FAIL') 150 actuals.append('FAIL')
150 elif r.actual == ResultType.Pass: 151 elif r.actual == ResultType.Pass:
151 actuals.append('PASS') 152 actuals.append('PASS')
152 elif r.actual == ResultType.Skip: 153 elif r.actual == ResultType.Skip:
153 actuals.append('SKIP') 154 actuals.append('SKIP')
155
156 # The time a test takes is a floating point number of seconds;
157 # if we were to encode this unmodified, then when we converted it
158 # to JSON it might make the file significantly larger. Instead
159 # we truncate the file to ten-thousandths of a second, which is
160 # probably more than good enough for most tests.
161 times.append(round(r.took, 4))
154 if not actuals: # pragma: untested 162 if not actuals: # pragma: untested
155 actuals.append('SKIP') 163 actuals.append('SKIP')
156 return ' '.join(actuals) 164 value['actual'] = ' '.join(actuals)
157 165 value['times'] = times
166 return value
158 167
159 def _add_path_to_trie(trie, path, value): 168 def _add_path_to_trie(trie, path, value):
160 if TEST_SEPARATOR not in path: 169 if TEST_SEPARATOR not in path:
161 trie[path] = value 170 trie[path] = value
162 return 171 return
163 directory, rest = path.split(TEST_SEPARATOR, 1) 172 directory, rest = path.split(TEST_SEPARATOR, 1)
164 if directory not in trie: 173 if directory not in trie:
165 trie[directory] = {} 174 trie[directory] = {}
166 _add_path_to_trie(trie[directory], rest, value) 175 _add_path_to_trie(trie[directory], rest, value)
167 176
(...skipping 15 matching lines...) Expand all
183 'filename="full_results.json"') 192 'filename="full_results.json"')
184 lines.append('Content-Type: application/json') 193 lines.append('Content-Type: application/json')
185 lines.append('') 194 lines.append('')
186 lines.append(json.dumps(test_results)) 195 lines.append(json.dumps(test_results))
187 196
188 lines.append('--' + BOUNDARY + '--') 197 lines.append('--' + BOUNDARY + '--')
189 lines.append('') 198 lines.append('')
190 body = CRLF.join(lines) 199 body = CRLF.join(lines)
191 content_type = 'multipart/form-data; boundary=%s' % BOUNDARY 200 content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
192 return content_type, body 201 return content_type, body
OLDNEW
« no previous file with comments | « no previous file | typ/tests/json_results_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698