| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The LUCI Authors. All rights reserved. | 2 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import json | 6 import json |
| 7 import logging |
| 7 import os | 8 import os |
| 8 import subprocess | 9 import subprocess |
| 9 import sys | 10 import sys |
| 10 import unittest | 11 import unittest |
| 11 | 12 |
| 12 import repo_test_util | 13 import repo_test_util |
| 13 | 14 |
| 14 | 15 |
| 15 class TestAutoroll(repo_test_util.RepoTest): | 16 class TestAutoroll(repo_test_util.RepoTest): |
| 16 def run_roll(self, repo, *args): | 17 def run_roll(self, repo, *args): |
| 17 """Runs the autoroll command and returns JSON. | 18 """Runs the autoroll command and returns JSON. |
| 18 Does not commit the resulting roll. | 19 Does not commit the resulting roll. |
| 19 """ | 20 """ |
| 20 with repo_test_util.in_directory(repo['root']), \ | 21 with repo_test_util.in_directory(repo['root']), \ |
| 21 repo_test_util.temporary_file() as tempfile_path: | 22 repo_test_util.temporary_file() as tempfile_path: |
| 22 subprocess.check_output([ | 23 try: |
| 23 sys.executable, self._recipe_tool, | 24 subprocess.check_output([ |
| 24 '--package', os.path.join( | 25 sys.executable, self._recipe_tool, |
| 25 repo['root'], 'infra', 'config', 'recipes.cfg'), | 26 '--package', os.path.join( |
| 26 '--use-bootstrap', | 27 repo['root'], 'infra', 'config', 'recipes.cfg'), |
| 27 'autoroll', | 28 '--use-bootstrap', |
| 28 '--output-json', tempfile_path | 29 'autoroll', |
| 29 ] + list(args), stderr=subprocess.STDOUT) | 30 '--output-json', tempfile_path |
| 31 ] + list(args), stderr=subprocess.STDOUT) |
| 32 except subprocess.CalledProcessError as ex: |
| 33 logging.error('Failed subprocess output: %s', ex.output) |
| 34 raise |
| 30 with open(tempfile_path) as f: | 35 with open(tempfile_path) as f: |
| 31 return json.load(f) | 36 return json.load(f) |
| 32 | 37 |
| 33 def test_empty(self): | 38 def test_empty(self): |
| 34 """Tests the scenario where there are no roll candidates. | 39 """Tests the scenario where there are no roll candidates. |
| 35 """ | 40 """ |
| 36 repos = self.repo_setup({ | 41 repos = self.repo_setup({ |
| 37 'a': [], | 42 'a': [], |
| 38 }) | 43 }) |
| 39 | 44 |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 '--project=c', | 508 '--project=c', |
| 504 '--project=d', | 509 '--project=d', |
| 505 ) | 510 ) |
| 506 self.assertFalse(roll_result['success']) | 511 self.assertFalse(roll_result['success']) |
| 507 self.assertFalse(bool(roll_result['roll_details'])) | 512 self.assertFalse(bool(roll_result['roll_details'])) |
| 508 self.assertFalse(bool(roll_result['rejected_candidates_details'])) | 513 self.assertFalse(bool(roll_result['rejected_candidates_details'])) |
| 509 | 514 |
| 510 | 515 |
| 511 if __name__ == '__main__': | 516 if __name__ == '__main__': |
| 512 sys.exit(unittest.main()) | 517 sys.exit(unittest.main()) |
| OLD | NEW |