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

Unified Diff: recipe_engine/step_runner.py

Issue 1785543004: Split Placeholder into InputPlaceholder and OutputPlaceholder. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Fix nits. 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_engine/step_runner.py
diff --git a/recipe_engine/step_runner.py b/recipe_engine/step_runner.py
index 2cd05d3576c4bacd0c501c2156d871dbcdeecd83..ae127e99692fabda3d9545dc8ff4cd0eaac94dc0 100644
--- a/recipe_engine/step_runner.py
+++ b/recipe_engine/step_runner.py
@@ -431,7 +431,7 @@ class SimulationStepRunner(StepRunner):
# Result of 'render_step'.
Placeholders = collections.namedtuple(
- 'Placeholders', ['cmd', 'stdout', 'stderr', 'stdin'])
+ 'Placeholders', ['inputs_cmd', 'outputs_cmd', 'stdout', 'stderr', 'stdin'])
def render_step(step, step_test):
@@ -448,14 +448,21 @@ def render_step(step, step_test):
rendered_step = dict(step)
# Process 'cmd', rendering placeholders there.
- placeholders = collections.defaultdict(lambda: collections.defaultdict(list))
+ input_phs = collections.defaultdict(lambda: collections.defaultdict(list))
+ output_phs = collections.defaultdict(lambda: collections.defaultdict(list))
new_cmd = []
for item in step.get('cmd', []):
if isinstance(item, util.Placeholder):
module_name, placeholder_name = item.name_pieces
- tdata = step_test.pop_placeholder(item.name_pieces)
+ if isinstance(item, util.InputPlaceholder):
+ tdata = step_test.pop_input_placeholder(item.name_pieces)
iannucci 2016/03/12 03:36:12 not needed: inputs are never mocked
stgao 2016/03/22 05:56:43 Reverted to the old approach. We still need a def
+ input_phs[module_name][placeholder_name].append((item, tdata))
+ else:
+ assert isinstance(item, util.OutputPlaceholder), (
+ 'Not an OutputPlaceholder: %r' % item)
+ tdata = step_test.pop_output_placeholder(item.name_pieces)
+ output_phs[module_name][placeholder_name].append((item, tdata))
new_cmd.extend(item.render(tdata))
- placeholders[module_name][placeholder_name].append((item, tdata))
else:
new_cmd.append(item)
rendered_step['cmd'] = new_cmd
@@ -466,21 +473,26 @@ def render_step(step, step_test):
placeholder = step.get(key)
tdata = None
if placeholder:
- assert isinstance(placeholder, util.Placeholder), key
+ if key == 'stdin':
+ assert isinstance(placeholder, util.InputPlaceholder), key
+ else:
+ assert isinstance(placeholder, util.OutputPlaceholder), key
tdata = getattr(step_test, key)
placeholder.render(tdata)
assert placeholder.backing_file
rendered_step[key] = placeholder.backing_file
stdio_placeholders[key] = (placeholder, tdata)
- return rendered_step, Placeholders(cmd=placeholders, **stdio_placeholders)
+ return rendered_step, Placeholders(
+ inputs_cmd=input_phs, outputs_cmd=output_phs, **stdio_placeholders)
def construct_step_result(step, retcode, placeholders):
"""Constructs a StepData step result from step return data.
- The main purpose of this function is to add placeholder results into the
- step result where placeholders appeared in the input step.
+ The main purpose of this function is to add output placeholder results into
+ the step result where output placeholders appeared in the input step.
+ Also give input placeholders the chance to do the clean-up if needed.
"""
step_result = types.StepData(step, retcode)
@@ -488,8 +500,14 @@ def construct_step_result(step, retcode, placeholders):
class BlankObject(object):
pass
- # Placeholders inside step |cmd|.
- for module_name, pholders in placeholders.cmd.iteritems():
+ # Input placeholders inside step |cmd|.
+ for _, pholders in placeholders.inputs_cmd.iteritems():
+ for _, items in pholders.iteritems():
+ for ph, td in items:
+ ph.result(step_result.presentation, td)
+
+ # Output placeholders inside step |cmd|.
+ for module_name, pholders in placeholders.outputs_cmd.iteritems():
assert not hasattr(step_result, module_name)
o = BlankObject()
setattr(step_result, module_name, o)
@@ -504,7 +522,8 @@ def construct_step_result(step, retcode, placeholders):
assert not hasattr(step_result, key)
ph, td = getattr(placeholders, key)
result = ph.result(step_result.presentation, td) if ph else None
- setattr(step_result, key, result)
+ if key != 'stdin':
iannucci 2016/03/12 03:36:12 this looks wrong to me...? Not sure what this is s
stgao 2016/03/22 05:56:43 Reverted. However, I thought we don't want to inc
+ setattr(step_result, key, result)
return step_result

Powered by Google App Engine
This is Rietveld 408576698