| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 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 os | 6 import os |
| 7 import shutil | 7 import shutil |
| 8 import subprocess | 8 import subprocess |
| 9 import tempfile | 9 import tempfile |
| 10 import unittest | 10 import unittest |
| 11 | 11 |
| 12 import repo_test_util | 12 import repo_test_util |
| 13 from repo_test_util import ROOT_DIR | 13 from repo_test_util import ROOT_DIR |
| 14 | 14 |
| 15 | 15 |
| 16 class RecipeRepo(object): | 16 class RecipeRepo(object): |
| 17 def __init__(self): | 17 def __init__(self, recipes_path=''): |
| 18 self._root = tempfile.mkdtemp() | 18 self._root = tempfile.mkdtemp() |
| 19 os.makedirs(os.path.join(self._root, 'infra', 'config')) | 19 os.makedirs(os.path.join(self._root, 'infra', 'config')) |
| 20 self._recipes_cfg = os.path.join( | 20 self._recipes_cfg = os.path.join( |
| 21 self._root, 'infra', 'config', 'recipes.cfg') | 21 self._root, 'infra', 'config', 'recipes.cfg') |
| 22 with open(self._recipes_cfg, 'w') as fh: | 22 with open(self._recipes_cfg, 'w') as fh: |
| 23 fh.write(""" | 23 fh.write(""" |
| 24 api_version: 1 | 24 api_version: 1 |
| 25 project_id: "testproj" | 25 project_id: "testproj" |
| 26 recipes_path: "%s" |
| 26 deps { | 27 deps { |
| 27 project_id: "recipe_engine" | 28 project_id: "recipe_engine" |
| 28 url: "%s" | 29 url: "%s" |
| 29 branch: "master" | 30 branch: "master" |
| 30 revision: "HEAD" | 31 revision: "HEAD" |
| 31 } | 32 } |
| 32 """ % ROOT_DIR) | 33 """ % (recipes_path, ROOT_DIR)) |
| 33 self._recipes_dir = os.path.join(self._root, 'recipes') | 34 self._recipes_dir = os.path.join(self._root, 'recipes') |
| 34 os.mkdir(self._recipes_dir) | 35 os.mkdir(self._recipes_dir) |
| 35 self._modules_dir = os.path.join(self._root, 'recipe_modules') | 36 self._modules_dir = os.path.join(self._root, 'recipe_modules') |
| 36 os.mkdir(self._modules_dir) | 37 os.mkdir(self._modules_dir) |
| 37 | 38 |
| 38 def make_recipe(self, recipe, contents): | 39 def make_recipe(self, recipe, contents): |
| 39 with open(os.path.join(self._recipes_dir, '%s.py' % recipe), 'w') as fh: | 40 with open(os.path.join(self._recipes_dir, '%s.py' % recipe), 'w') as fh: |
| 40 fh.write(contents) | 41 fh.write(contents) |
| 41 | 42 |
| 42 def make_module(self, name, init_contents, api_contents): | 43 def make_module(self, name, init_contents, api_contents): |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 pass | 181 pass |
| 181 | 182 |
| 182 def GenTests(api): | 183 def GenTests(api): |
| 183 yield api.test('basic') + api.expect_exception('AssertionError') | 184 yield api.test('basic') + api.expect_exception('AssertionError') |
| 184 """) | 185 """) |
| 185 self._test_cmd(repo, ['simulation_test', 'train', 'unconsumed_assertion'], | 186 self._test_cmd(repo, ['simulation_test', 'train', 'unconsumed_assertion'], |
| 186 asserts=lambda stdout, stderr: self.assertRegexpMatches( | 187 asserts=lambda stdout, stderr: self.assertRegexpMatches( |
| 187 stdout + stderr, 'Unconsumed'), | 188 stdout + stderr, 'Unconsumed'), |
| 188 retcode=1) | 189 retcode=1) |
| 189 | 190 |
| 191 def test_run_recipe_help(self): |
| 192 with RecipeRepo(recipes_path='foo/bar') as repo: |
| 193 repo.make_recipe('do_nothing', """ |
| 194 DEPS = [] |
| 195 def RunSteps(api): |
| 196 pass |
| 197 """) |
| 198 subp = subprocess.Popen( |
| 199 repo.recipes_cmd + ['run', 'do_nothing'], |
| 200 stdout=subprocess.PIPE) |
| 201 stdout, _ = subp.communicate() |
| 202 self.assertRegexpMatches( |
| 203 stdout, r'from the root of a \'testproj\' checkout') |
| 204 self.assertRegexpMatches( |
| 205 stdout, r'\./foo/bar/recipes\.py --package=.* run .* do_nothing') |
| 206 |
| 207 |
| 208 |
| 209 |
| 210 |
| 190 if __name__ == '__main__': | 211 if __name__ == '__main__': |
| 191 unittest.main() | 212 unittest.main() |
| OLD | NEW |