Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Unit tests for upload_test_results.py.""" | 6 """Unit tests for upload_test_results.py.""" |
| 7 | 7 |
| 8 import json | 8 import json |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 }], | 72 }], |
| 73 } | 73 } |
| 74 results = upload_test_results.get_results_map_from_json( | 74 results = upload_test_results.get_results_map_from_json( |
| 75 json.dumps(contents)) | 75 json.dumps(contents)) |
| 76 self.assertEquals(results['Disabled.Test'][0].DISABLED, | 76 self.assertEquals(results['Disabled.Test'][0].DISABLED, |
| 77 results['Disabled.Test'][0].modifier) | 77 results['Disabled.Test'][0].modifier) |
| 78 self.assertEquals(results['Disabled.Test'][0].DISABLED, | 78 self.assertEquals(results['Disabled.Test'][0].DISABLED, |
| 79 results['Skipped.Test'][0].modifier) | 79 results['Skipped.Test'][0].modifier) |
| 80 | 80 |
| 81 @mock.patch('test_results_uploader.upload_test_results') | 81 @mock.patch('test_results_uploader.upload_test_results') |
| 82 def test_main(self, uploader_mock): | 82 def test_main_gtest_json(self, uploader_mock): |
| 83 contents = { | 83 contents = { |
| 84 'per_iteration_data': [{ | 84 'per_iteration_data': [{ |
| 85 'Fake.Test': [ | 85 'Fake.Test': [ |
| 86 {'status': 'XXX', 'elapsed_time_ms': 1000}, | 86 {'status': 'XXX', 'elapsed_time_ms': 1000}, |
| 87 ], | 87 ], |
| 88 }], | 88 }], |
| 89 } | 89 } |
| 90 result_directory = tempfile.mkdtemp() | 90 result_directory = tempfile.mkdtemp() |
| 91 input_json_file_path = os.path.join(result_directory, 'results.json') | 91 input_json_file_path = os.path.join(result_directory, 'results.json') |
| 92 with open(input_json_file_path, 'w') as f: | 92 with open(input_json_file_path, 'w') as f: |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 107 os.path.join(result_directory, | 107 os.path.join(result_directory, |
| 108 upload_test_results.TIMES_MS_FILENAME))] | 108 upload_test_results.TIMES_MS_FILENAME))] |
| 109 uploader_mock.assert_called_with( | 109 uploader_mock.assert_called_with( |
| 110 'foo', | 110 'foo', |
| 111 [('builder', 'DUMMY_BUILDER_NAME'), | 111 [('builder', 'DUMMY_BUILDER_NAME'), |
| 112 ('testtype', 'foo'), | 112 ('testtype', 'foo'), |
| 113 ('master', 'sauron')], files, 120) | 113 ('master', 'sauron')], files, 120) |
| 114 finally: | 114 finally: |
| 115 shutil.rmtree(result_directory) | 115 shutil.rmtree(result_directory) |
| 116 | 116 |
| 117 @mock.patch('test_results_uploader.upload_test_results') | |
| 118 def test_main_full_results_json(self, uploader_mock): | |
| 119 contents = { | |
| 120 'tests': { | |
| 121 'mojom_tests': { | |
| 122 'parse': { | |
| 123 'ast_unittest': { | |
| 124 'ASTTest': { | |
| 125 'testNodeBase': { | |
| 126 'expected': 'PASS', | |
| 127 'actual': 'PASS' | |
| 128 } | |
| 129 } | |
| 130 } | |
| 131 } | |
| 132 } | |
| 133 }, | |
| 134 'interrupted': False, | |
| 135 'path_delimiter': '.', | |
| 136 'version': 3, | |
| 137 'seconds_since_epoch': 1406662283.764424, | |
| 138 'num_failures_by_type': { | |
| 139 'FAIL': 0, | |
| 140 'PASS': 1 | |
| 141 } | |
| 142 } | |
| 143 result_directory = tempfile.mkdtemp() | |
| 144 input_json_file_path = os.path.join(result_directory, 'results.json') | |
| 145 with open(input_json_file_path, 'w') as f: | |
| 146 json.dump(contents, f) | |
| 147 try: | |
|
Paweł Hajdan Jr.
2016/11/07 08:30:27
nit: Since "finally" removes the directory, should
nednguyen
2016/11/07 14:26:24
Done.
| |
| 148 upload_test_results.main([ | |
| 149 '--test-type=foo', | |
| 150 '--input-json=%s' % input_json_file_path, | |
| 151 '--results-directory=%s' % result_directory, | |
| 152 '--test-results-server=foo', | |
| 153 '--master-name=sauron', | |
| 154 ]) | |
| 155 files = [(os.path.basename(input_json_file_path), input_json_file_path)] | |
| 156 uploader_mock.assert_called_with( | |
| 157 'foo', | |
| 158 [('builder', 'DUMMY_BUILDER_NAME'), | |
| 159 ('testtype', 'foo'), | |
| 160 ('master', 'sauron')], files, 120) | |
| 161 finally: | |
| 162 shutil.rmtree(result_directory) | |
| 163 | |
| 117 | 164 |
| 165 | |
| 118 if __name__ == '__main__': | 166 if __name__ == '__main__': |
| 119 unittest.main() | 167 unittest.main() |
| OLD | NEW |