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