Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 DEPS = [ | 5 DEPS = [ |
| 6 'path', | 6 'path', |
| 7 'properties', | |
| 8 'python', | |
| 7 'raw_io', | 9 'raw_io', |
| 8 'step', | 10 'step', |
| 9 ] | 11 ] |
| 10 | 12 |
| 11 | 13 |
| 12 def RunSteps(api): | 14 def RunSteps(api): |
| 13 # Read command's stdout and stderr. | 15 # Read command's stdout and stderr. |
| 14 step_result = api.step('echo', ['echo', 'Hello World'], | 16 step_result = api.step('echo', ['echo', 'Hello World'], |
| 15 stdout=api.raw_io.output(), | 17 stdout=api.raw_io.output(), |
| 16 stderr=api.raw_io.output()) | 18 stderr=api.raw_io.output()) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 'leak stdout', ['echo', 'leaking'], | 51 'leak stdout', ['echo', 'leaking'], |
| 50 stdout=api.raw_io.output(leak_to=api.path['slave_build'].join('out.txt')), | 52 stdout=api.raw_io.output(leak_to=api.path['slave_build'].join('out.txt')), |
| 51 step_test_data=( | 53 step_test_data=( |
| 52 lambda: api.raw_io.test_api.stream_output('leaking\n'))) | 54 lambda: api.raw_io.test_api.stream_output('leaking\n'))) |
| 53 assert step_result.stdout == 'leaking\n' | 55 assert step_result.stdout == 'leaking\n' |
| 54 | 56 |
| 55 api.step('list temp dir', ['ls', api.raw_io.output_dir()]) | 57 api.step('list temp dir', ['ls', api.raw_io.output_dir()]) |
| 56 api.step('leak dir', ['ls', api.raw_io.output_dir( | 58 api.step('leak dir', ['ls', api.raw_io.output_dir( |
| 57 leak_to=api.path['slave_build'].join('out'))]) | 59 leak_to=api.path['slave_build'].join('out'))]) |
| 58 | 60 |
| 61 # Example of overriding default mocked output for a single named output. | |
| 62 step_result = api.python.inline( | |
| 63 'override_default_mock', | |
| 64 """ | |
| 65 import sys | |
| 66 with open(sys.argv[1], 'w') as f: | |
| 67 f.write(%r) | |
| 68 """ % api.properties.get('some_prop', 'good_value'), | |
| 69 args=[api.raw_io.output(name='test')], | |
| 70 step_test_data=( | |
| 71 lambda: api.raw_io.test_api.output('second_bad_value', name='test'))) | |
| 72 assert step_result.raw_io.outputs['test'] == 'good_value' | |
| 73 assert step_result.raw_io.output == 'good_value' | |
| 74 | |
| 59 | 75 |
| 60 def GenTests(api): | 76 def GenTests(api): |
| 77 # This test shows that you can override a specific placeholder, even with | |
| 78 # default `step_test_data`. However, since this recipe is ACTUALLY run in | |
| 79 # the presubmit, we need to do a trick with properties: | |
| 80 # When run for real, "some_prop" will be "good_value" and pass. | |
| 81 # When run for simulation, we override this property to provide a bad value, | |
| 82 # AND the default step_test_data ALSO provides another bad value, | |
|
iannucci
2016/03/22 22:54:24
s/default step_test_data/default step_test_data in
stgao
2016/03/22 23:40:25
Done.
| |
| 83 # The simulation passes ONLY because of the 'override_default_mock' below. | |
| 61 yield (api.test('basic') + | 84 yield (api.test('basic') + |
| 85 api.properties(some_prop='bad_value') + | |
| 62 api.step_data('echo', | 86 api.step_data('echo', |
| 63 stdout=api.raw_io.output('Hello World\n'), | 87 stdout=api.raw_io.output('Hello World\n'), |
| 64 stderr=api.raw_io.output('')) + | 88 stderr=api.raw_io.output('')) + |
| 65 api.step_data('cat', | 89 api.step_data('cat', |
| 66 stdout=api.raw_io.output('hello'))) | 90 stdout=api.raw_io.output('hello')) + |
| 91 api.step_data('override_default_mock', | |
| 92 api.raw_io.output('good_value', name='test')) | |
| 93 ) | |
| OLD | NEW |