| OLD | NEW |
| 1 # Copyright 2017 The LUCI Authors. All rights reserved. | 1 # Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 from recipe_engine import recipe_api, config | 5 from recipe_engine import recipe_api, config |
| 6 | 6 |
| 7 DEPS = [ | 7 DEPS = [ |
| 8 'context', | 8 'context', |
| 9 'path', | 9 'path', |
| 10 'step', | 10 'step', |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 # can change cwd | 23 # can change cwd |
| 24 api.step('mk subdir', ['mkdir', 'subdir']) | 24 api.step('mk subdir', ['mkdir', 'subdir']) |
| 25 with api.context(cwd=api.path['start_dir'].join('subdir')): | 25 with api.context(cwd=api.path['start_dir'].join('subdir')): |
| 26 api.step('subdir step', ['bash', '-c', 'pwd']) | 26 api.step('subdir step', ['bash', '-c', 'pwd']) |
| 27 api.step('other subdir step', ['bash', '-c', 'echo hi again!']) | 27 api.step('other subdir step', ['bash', '-c', 'echo hi again!']) |
| 28 | 28 |
| 29 # can set envvars | 29 # can set envvars |
| 30 with api.context(env={"HELLO": "WORLD", "HOME": None}): | 30 with api.context(env={"HELLO": "WORLD", "HOME": None}): |
| 31 api.step('env step', ['bash', '-c', 'echo $HELLO; echo $HOME']) | 31 api.step('env step', ['bash', '-c', 'echo $HELLO; echo $HOME']) |
| 32 | 32 |
| 33 # %-formats are errors (for now). Double-% escape them. |
| 34 bad_examples = ["%format", "%s"] |
| 35 for example in bad_examples: |
| 36 try: |
| 37 with api.context(env={"BAD": example}): |
| 38 assert False # pragma: no cover |
| 39 except ValueError: |
| 40 pass |
| 41 |
| 42 # this is fine though: |
| 43 api.context(env={"FINE": "%%format"}) |
| 44 |
| 33 # can increment nest level... note that this is a low level api, prefer | 45 # can increment nest level... note that this is a low level api, prefer |
| 34 # api.step.nest instead: | 46 # api.step.nest instead: |
| 35 # YES: | 47 # YES: |
| 36 with api.step.nest('nested'): | 48 with api.step.nest('nested'): |
| 37 api.step('properly indented', ['bash', '-c', 'echo yay!']) | 49 api.step('properly indented', ['bash', '-c', 'echo yay!']) |
| 38 # AVOID: | 50 # AVOID: |
| 39 with api.context(increment_nest_level=True): | 51 with api.context(increment_nest_level=True): |
| 40 api.step('indented with wrong name', ['bash', '-c', 'echo indent?']) | 52 api.step('indented with wrong name', ['bash', '-c', 'echo indent?']) |
| 41 | 53 |
| 42 | 54 |
| 43 def GenTests(api): | 55 def GenTests(api): |
| 44 yield api.test('basic') | 56 yield api.test('basic') |
| OLD | NEW |