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

Unified 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: Address comments. 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 side-by-side diff with in-line comments
Download patch
Index: recipe_modules/raw_io/example.py
diff --git a/recipe_modules/raw_io/example.py b/recipe_modules/raw_io/example.py
index 3bcbc44498a110f5e986981ab462c871fccdd222..0f3495da8a127dd730f706b20a2bca1db247c341 100644
--- a/recipe_modules/raw_io/example.py
+++ b/recipe_modules/raw_io/example.py
@@ -4,6 +4,8 @@
DEPS = [
'path',
+ 'properties',
+ 'python',
'raw_io',
'step',
]
@@ -56,11 +58,36 @@ def RunSteps(api):
api.step('leak dir', ['ls', api.raw_io.output_dir(
leak_to=api.path['slave_build'].join('out'))])
+ # Example of overriding default mocked output for a single named output.
+ step_result = api.python.inline(
+ 'override_default_mock',
+ """
+ import sys
+ with open(sys.argv[1], 'w') as f:
+ f.write(%r)
+ """ % api.properties.get('some_prop', 'good_value'),
+ args=[api.raw_io.output(name='test')],
+ step_test_data=(
+ lambda: api.raw_io.test_api.output('second_bad_value', name='test')))
+ assert step_result.raw_io.outputs['test'] == 'good_value'
+ assert step_result.raw_io.output == 'good_value'
+
def GenTests(api):
+ # This test shows that you can override a specific placeholder, even with
+ # default `step_test_data`. However, since this recipe is ACTUALLY run in
+ # the presubmit, we need to do a trick with properties:
+ # When run for real, "some_prop" will be "good_value" and pass.
+ # When run for simulation, we override this property to provide a bad value,
+ # 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.
+ # The simulation passes ONLY because of the 'override_default_mock' below.
yield (api.test('basic') +
+ api.properties(some_prop='bad_value') +
api.step_data('echo',
stdout=api.raw_io.output('Hello World\n'),
stderr=api.raw_io.output('')) +
api.step_data('cat',
- stdout=api.raw_io.output('hello')))
+ stdout=api.raw_io.output('hello')) +
+ api.step_data('override_default_mock',
+ api.raw_io.output('good_value', name='test'))
+ )

Powered by Google App Engine
This is Rietveld 408576698