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

Side by Side Diff: recipe_engine/simulation_test.py

Issue 2245113002: Track step nesting in StreamEngine. (Closed) Base URL: https://github.com/luci/recipes-py@emit-initial-properties
Patch Set: Created 4 years, 4 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
OLDNEW
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 """Provides simulator test coverage for individual recipes.""" 5 """Provides simulator test coverage for individual recipes."""
6 6
7 import StringIO
8 import contextlib
7 import logging 9 import logging
8 import re 10 import re
9 import os 11 import os
10 import sys 12 import sys
11 13
12 from . import env 14 from . import env
15 from . import stream
13 import expect_tests 16 import expect_tests
14 17
15 # This variable must be set in the dynamic scope of the functions in this file. 18 # This variable must be set in the dynamic scope of the functions in this file.
16 # We do this instead of passing because the threading system of expect tests 19 # We do this instead of passing because the threading system of expect tests
17 # doesn't know how to serialize it. 20 # doesn't know how to serialize it.
18 _UNIVERSE = None 21 _UNIVERSE = None
19 22
23
24 class SimulationAnnotatorStreamEngine(stream.AnnotatorStreamEngine):
dnj 2016/08/15 17:33:53 Now that the annotator stream engine tracks state,
25
26 def __init__(self):
27 self._step_buffer_map = {}
28 super(SimulationAnnotatorStreamEngine, self).__init__(
29 self.step_buffer(None))
30
31 def step_buffer(self, step_name):
32 return self._step_buffer_map.setdefault(step_name, StringIO.StringIO())
33
34 def new_step_stream(self, step_name, allow_subannotations=False,
35 nested=False):
36 return self._create_step_stream(step_name, self.step_buffer(step_name),
37 allow_subannotations, nested)
38
39
20 def RunRecipe(test_data): 40 def RunRecipe(test_data):
21 from . import config_types 41 from . import config_types
22 from . import loader 42 from . import loader
23 from . import run 43 from . import run
24 from . import step_runner 44 from . import step_runner
25 from . import stream 45 from . import stream
26 46
27 config_types.ResetTostringFns() 47 config_types.ResetTostringFns()
28 with stream.StreamEngineInvariants() as stream_engine: 48
29 step_runner = step_runner.SimulationStepRunner(stream_engine, test_data) 49 annotator = SimulationAnnotatorStreamEngine()
dnj 2016/08/15 17:33:53 We pass the annotator directly to the stream engin
50 stream_engine = stream.ProductStreamEngine(
51 stream.StreamEngineInvariants(),
52 annotator)
53 with stream_engine:
54 step_runner = step_runner.SimulationStepRunner(stream_engine, test_data,
55 annotator)
30 56
31 engine = run.RecipeEngine(step_runner, test_data.properties, _UNIVERSE) 57 engine = run.RecipeEngine(step_runner, test_data.properties, _UNIVERSE)
32 recipe_script = _UNIVERSE.load_recipe(test_data.properties['recipe']) 58 recipe_script = _UNIVERSE.load_recipe(test_data.properties['recipe'])
33 api = loader.create_recipe_api(recipe_script.LOADED_DEPS, engine, test_data) 59 api = loader.create_recipe_api(recipe_script.LOADED_DEPS, engine, test_data)
34 result = engine.run(recipe_script, api) 60 result = engine.run(recipe_script, api)
35 61
36 # Don't include tracebacks in expectations because they are too sensitive to 62 # Don't include tracebacks in expectations because they are too sensitive to
37 # change. 63 # change.
38 result.result.pop('traceback', None) 64 result.result.pop('traceback', None)
39 65
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 'TESTING_SLAVENAME']: 137 'TESTING_SLAVENAME']:
112 if env_var in os.environ: 138 if env_var in os.environ:
113 logging.warn("Ignoring %s environment variable." % env_var) 139 logging.warn("Ignoring %s environment variable." % env_var)
114 os.environ.pop(env_var) 140 os.environ.pop(env_var)
115 141
116 global _UNIVERSE 142 global _UNIVERSE
117 _UNIVERSE = universe 143 _UNIVERSE = universe
118 144
119 expect_tests.main('recipe_simulation_test', GenerateTests, 145 expect_tests.main('recipe_simulation_test', GenerateTests,
120 cover_omit=cover_omit(), args=args) 146 cover_omit=cover_omit(), args=args)
OLDNEW
« no previous file with comments | « recipe_engine/run.py ('k') | recipe_engine/step_runner.py » ('j') | recipe_engine/step_runner.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698