Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: recipe_modules/raw_io/example.py

Issue 1773273003: Make output placeholders like json.output index-able by name. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Rebase. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « recipe_modules/raw_io/api.py ('k') | recipe_modules/raw_io/example.expected/basic.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 in RunSteps above ALSO provides another
83 # bad value, the simulation passes ONLY because of the
84 # 'override_default_mock' below.
61 yield (api.test('basic') + 85 yield (api.test('basic') +
86 api.properties(some_prop='bad_value') +
62 api.step_data('echo', 87 api.step_data('echo',
63 stdout=api.raw_io.output('Hello World\n'), 88 stdout=api.raw_io.output('Hello World\n'),
64 stderr=api.raw_io.output('')) + 89 stderr=api.raw_io.output('')) +
65 api.step_data('cat', 90 api.step_data('cat',
66 stdout=api.raw_io.output('hello'))) 91 stdout=api.raw_io.output('hello')) +
92 api.step_data('override_default_mock',
93 api.raw_io.output('good_value', name='test'))
94 )
OLDNEW
« no previous file with comments | « recipe_modules/raw_io/api.py ('k') | recipe_modules/raw_io/example.expected/basic.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698