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

Side by Side Diff: third_party/typ/typ/json_results.py

Issue 2690743002: Roll typ v0.9.9 -> v0.9.11 (5822dda0..f6afa2bb). (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
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
105 104
106 def make_upload_request(test_results_server, builder, master, testtype, 105 def make_upload_request(test_results_server, builder, master, testtype,
107 full_results): 106 full_results):
108 url = 'https://%s/testfile/upload' % test_results_server 107 if test_results_server.startswith('http'):
108 url = '%s/testfile/upload' % test_results_server
109 else:
110 url = 'https://%s/testfile/upload' % test_results_server
109 attrs = [('builder', builder), 111 attrs = [('builder', builder),
110 ('master', master), 112 ('master', master),
111 ('testtype', testtype)] 113 ('testtype', testtype)]
112 content_type, data = _encode_multipart_form_data(attrs, full_results) 114 content_type, data = _encode_multipart_form_data(attrs, full_results)
113 return url, content_type, data 115 return url, content_type, data
114 116
115 117
116 def exit_code_from_full_results(full_results): 118 def exit_code_from_full_results(full_results):
117 return 1 if num_failures(full_results) else 0 119 return 1 if num_failures(full_results) else 0
118 120
(...skipping 15 matching lines...) Expand all
134 # failed, but that's at least consistent with a test that is 136 # failed, but that's at least consistent with a test that is
135 # skipped every time. 137 # skipped every time.
136 names.remove(r.name) 138 names.remove(r.name)
137 return names 139 return names
138 140
139 141
140 def _passing_test_names(results): 142 def _passing_test_names(results):
141 return set(r.name for r in results.results if r.actual == ResultType.Pass) 143 return set(r.name for r in results.results if r.actual == ResultType.Pass)
142 144
143 145
144 def _actual_results_for_test(test_name, results): 146 def _results_for_test(test_name, results):
147 value = OrderedDict()
145 actuals = [] 148 actuals = []
149 times = []
146 for r in results.results: 150 for r in results.results:
147 if r.name == test_name: 151 if r.name == test_name:
148 if r.actual == ResultType.Failure: 152 if r.actual == ResultType.Failure:
149 actuals.append('FAIL') 153 actuals.append('FAIL')
150 elif r.actual == ResultType.Pass: 154 elif r.actual == ResultType.Pass:
151 actuals.append('PASS') 155 actuals.append('PASS')
152 elif r.actual == ResultType.Skip: 156 elif r.actual == ResultType.Skip:
153 actuals.append('SKIP') 157 actuals.append('SKIP')
158
159 # The time a test takes is a floating point number of seconds;
160 # if we were to encode this unmodified, then when we converted it
161 # to JSON it might make the file significantly larger. Instead
162 # we truncate the file to ten-thousandths of a second, which is
163 # probably more than good enough for most tests.
164 times.append(round(r.took, 4))
154 if not actuals: # pragma: untested 165 if not actuals: # pragma: untested
155 actuals.append('SKIP') 166 actuals.append('SKIP')
156 return ' '.join(actuals) 167 value['actual'] = ' '.join(actuals)
157 168 value['times'] = times
169 return value
158 170
159 def _add_path_to_trie(trie, path, value): 171 def _add_path_to_trie(trie, path, value):
160 if TEST_SEPARATOR not in path: 172 if TEST_SEPARATOR not in path:
161 trie[path] = value 173 trie[path] = value
162 return 174 return
163 directory, rest = path.split(TEST_SEPARATOR, 1) 175 directory, rest = path.split(TEST_SEPARATOR, 1)
164 if directory not in trie: 176 if directory not in trie:
165 trie[directory] = {} 177 trie[directory] = {}
166 _add_path_to_trie(trie[directory], rest, value) 178 _add_path_to_trie(trie[directory], rest, value)
167 179
(...skipping 15 matching lines...) Expand all
183 'filename="full_results.json"') 195 'filename="full_results.json"')
184 lines.append('Content-Type: application/json') 196 lines.append('Content-Type: application/json')
185 lines.append('') 197 lines.append('')
186 lines.append(json.dumps(test_results)) 198 lines.append(json.dumps(test_results))
187 199
188 lines.append('--' + BOUNDARY + '--') 200 lines.append('--' + BOUNDARY + '--')
189 lines.append('') 201 lines.append('')
190 body = CRLF.join(lines) 202 body = CRLF.join(lines)
191 content_type = 'multipart/form-data; boundary=%s' % BOUNDARY 203 content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
192 return content_type, body 204 return content_type, body
OLDNEW
« no previous file with comments | « third_party/typ/typ/fakes/tests/test_result_server_fake_test.py ('k') | third_party/typ/typ/tests/json_results_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698