| OLD | NEW |
| 1 # Copyright 2014 The LUCI Authors. All rights reserved. | 1 # Copyright 2014 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 DEPS = [ | 5 DEPS = [ |
| 6 'path', | 6 'path', |
| 7 'properties', | 7 'properties', |
| 8 'python', | 8 'python', |
| 9 'raw_io', | 9 'raw_io', |
| 10 'step', | 10 'step', |
| 11 ] | 11 ] |
| 12 | 12 |
| 13 | 13 |
| 14 def RunSteps(api): | 14 def RunSteps(api): |
| 15 # Read command's stdout and stderr. | 15 # Read command's stdout and stderr. |
| 16 step_result = api.step('echo', ['echo', 'Hello World'], | 16 step_result = api.step('echo', ['echo', 'Hello World'], |
| 17 stdout=api.raw_io.output(), | 17 stdout=api.raw_io.output(), |
| 18 stderr=api.raw_io.output()) | 18 stderr=api.raw_io.output()) |
| 19 assert step_result.stdout == 'Hello World\n' | 19 assert step_result.stdout == 'Hello World\n' |
| 20 assert step_result.stderr == '' | 20 assert step_result.stderr == '' |
| 21 | 21 |
| 22 # Pass stuff to command's stdin, read it from stdout. | 22 # Pass stuff to command's stdin, read it from stdout. |
| 23 step_result = api.step('cat', ['cat'], | 23 step_result = api.step('cat', ['cat'], |
| 24 stdin=api.raw_io.input(data='hello'), | 24 stdin=api.raw_io.text_input(data='hello'), |
| 25 stdout=api.raw_io.output('out')) | 25 stdout=api.raw_io.output('out')) |
| 26 assert step_result.stdout == 'hello' | 26 assert step_result.stdout == 'hello' |
| 27 | 27 |
| 28 # TODO(martiniss): comment back in this test case |
| 29 step_result = api.step('cat', ['echo'], |
| 30 stdin=api.raw_io.input(data='\xe2hello'), |
| 31 stdout=api.raw_io.output('\xe2hello')) |
| 32 import pdb; pdb.set_trace() |
| 33 assert step_result.stdout == '\xe2hello' |
| 34 |
| 28 # Example of auto-mocking stdout. '\n' appended to mock 'echo' behavior. | 35 # Example of auto-mocking stdout. '\n' appended to mock 'echo' behavior. |
| 29 step_result = api.step('automock', ['echo', 'huh'], | 36 step_result = api.step('automock', ['echo', 'huh'], |
| 30 stdout=api.raw_io.output('out'), | 37 stdout=api.raw_io.output('out'), |
| 31 step_test_data=( | 38 step_test_data=( |
| 32 lambda: api.raw_io.test_api.stream_output('huh\n'))) | 39 lambda: api.raw_io.test_api.stream_output('huh\n'))) |
| 33 assert step_result.stdout == 'huh\n' | 40 assert step_result.stdout == 'huh\n' |
| 34 | 41 |
| 35 # Example of auto-mocking stdout + stderr. | 42 # Example of auto-mocking stdout + stderr. |
| 36 step_result = api.step( | 43 step_result = api.step( |
| 37 'automock (fail)', ['bash', '-c', 'echo blah && echo fail 1>&2'], | 44 'automock (fail)', ['bash', '-c', 'echo blah && echo fail 1>&2'], |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 yield (api.test('basic') + | 92 yield (api.test('basic') + |
| 86 api.properties(some_prop='bad_value') + | 93 api.properties(some_prop='bad_value') + |
| 87 api.step_data('echo', | 94 api.step_data('echo', |
| 88 stdout=api.raw_io.output('Hello World\n'), | 95 stdout=api.raw_io.output('Hello World\n'), |
| 89 stderr=api.raw_io.output('')) + | 96 stderr=api.raw_io.output('')) + |
| 90 api.step_data('cat', | 97 api.step_data('cat', |
| 91 stdout=api.raw_io.output('hello')) + | 98 stdout=api.raw_io.output('hello')) + |
| 92 api.step_data('override_default_mock', | 99 api.step_data('override_default_mock', |
| 93 api.raw_io.output('good_value', name='test')) | 100 api.raw_io.output('good_value', name='test')) |
| 94 ) | 101 ) |
| OLD | NEW |