| 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 |
| 10 import shutil |
| 11 import sys |
| 12 import tempfile |
| 9 import unittest | 13 import unittest |
| 10 | 14 |
| 15 sys.path.insert(0, os.path.join( |
| 16 os.path.dirname(__file__), '..', '..', '..', '..')) |
| 17 import common.env |
| 18 common.env.Install() |
| 19 import mock |
| 20 |
| 11 import upload_test_results | 21 import upload_test_results |
| 12 | 22 |
| 13 | 23 |
| 14 class UploadTestResultsTest(unittest.TestCase): | 24 class UploadTestResultsTest(unittest.TestCase): |
| 15 | 25 |
| 16 def setUp(self): | 26 def setUp(self): |
| 17 pass | 27 pass |
| 18 | 28 |
| 19 def test_no_test_data(self): | 29 def test_no_test_data(self): |
| 20 results = upload_test_results.get_results_map_from_json( | 30 results = upload_test_results.get_results_map_from_json( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 ], | 71 ], |
| 62 }], | 72 }], |
| 63 } | 73 } |
| 64 results = upload_test_results.get_results_map_from_json( | 74 results = upload_test_results.get_results_map_from_json( |
| 65 json.dumps(contents)) | 75 json.dumps(contents)) |
| 66 self.assertEquals(results['Disabled.Test'][0].DISABLED, | 76 self.assertEquals(results['Disabled.Test'][0].DISABLED, |
| 67 results['Disabled.Test'][0].modifier) | 77 results['Disabled.Test'][0].modifier) |
| 68 self.assertEquals(results['Disabled.Test'][0].DISABLED, | 78 self.assertEquals(results['Disabled.Test'][0].DISABLED, |
| 69 results['Skipped.Test'][0].modifier) | 79 results['Skipped.Test'][0].modifier) |
| 70 | 80 |
| 81 @mock.patch('test_results_uploader.upload_test_results') |
| 82 def test_main(self, uploader_mock): |
| 83 contents = { |
| 84 'per_iteration_data': [{ |
| 85 'Fake.Test': [ |
| 86 {'status': 'XXX', 'elapsed_time_ms': 1000}, |
| 87 ], |
| 88 }], |
| 89 } |
| 90 result_directory = tempfile.mkdtemp() |
| 91 input_json_file_path = os.path.join(result_directory, 'results.json') |
| 92 with open(input_json_file_path, 'w') as f: |
| 93 json.dump(contents, f) |
| 94 try: |
| 95 upload_test_results.main([ |
| 96 '--test-type=foo', |
| 97 '--input-json=%s' % input_json_file_path, |
| 98 '--results-directory=%s' % result_directory, |
| 99 '--test-results-server=foo', |
| 100 '--master-name=sauron', |
| 101 ]) |
| 102 files = [ |
| 103 ('full_results.json', |
| 104 os.path.join(result_directory, |
| 105 upload_test_results.FULL_RESULTS_FILENAME)), |
| 106 ('times_ms.json', |
| 107 os.path.join(result_directory, |
| 108 upload_test_results.TIMES_MS_FILENAME))] |
| 109 uploader_mock.assert_called_with( |
| 110 'foo', |
| 111 [('builder', 'DUMMY_BUILDER_NAME'), |
| 112 ('testtype', 'foo'), |
| 113 ('master', 'sauron')], files, 120) |
| 114 finally: |
| 115 shutil.rmtree(result_directory) |
| 116 |
| 71 | 117 |
| 72 if __name__ == '__main__': | 118 if __name__ == '__main__': |
| 73 unittest.main() | 119 unittest.main() |
| OLD | NEW |