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 """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): |
| 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, nest_level): |
| 35 return self._create_step_stream( |
| 36 step_name, |
| 37 self.step_buffer(step_name), |
| 38 allow_subannotations, |
| 39 nest_level) |
| 40 |
| 41 |
20 def RunRecipe(test_data): | 42 def RunRecipe(test_data): |
21 from . import config_types | 43 from . import config_types |
22 from . import loader | 44 from . import loader |
23 from . import run | 45 from . import run |
24 from . import step_runner | 46 from . import step_runner |
25 from . import stream | 47 from . import stream |
26 | 48 |
27 config_types.ResetTostringFns() | 49 config_types.ResetTostringFns() |
28 with stream.StreamEngineInvariants() as stream_engine: | 50 |
29 step_runner = step_runner.SimulationStepRunner(stream_engine, test_data) | 51 annotator = SimulationAnnotatorStreamEngine() |
| 52 stream_engine = stream.ProductStreamEngine( |
| 53 stream.StreamEngineInvariants(), |
| 54 annotator) |
| 55 with stream_engine: |
| 56 step_runner = step_runner.SimulationStepRunner(stream_engine, test_data, |
| 57 annotator) |
30 | 58 |
31 engine = run.RecipeEngine(step_runner, test_data.properties, _UNIVERSE) | 59 engine = run.RecipeEngine(step_runner, test_data.properties, _UNIVERSE) |
32 recipe_script = _UNIVERSE.load_recipe(test_data.properties['recipe']) | 60 recipe_script = _UNIVERSE.load_recipe(test_data.properties['recipe']) |
33 api = loader.create_recipe_api(recipe_script.LOADED_DEPS, engine, test_data) | 61 api = loader.create_recipe_api(recipe_script.LOADED_DEPS, engine, test_data) |
34 result = engine.run(recipe_script, api) | 62 result = engine.run(recipe_script, api) |
35 | 63 |
36 # Don't include tracebacks in expectations because they are too sensitive to | 64 # Don't include tracebacks in expectations because they are too sensitive to |
37 # change. | 65 # change. |
38 result.result.pop('traceback', None) | 66 result.result.pop('traceback', None) |
39 | 67 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 'TESTING_SLAVENAME']: | 139 'TESTING_SLAVENAME']: |
112 if env_var in os.environ: | 140 if env_var in os.environ: |
113 logging.warn("Ignoring %s environment variable." % env_var) | 141 logging.warn("Ignoring %s environment variable." % env_var) |
114 os.environ.pop(env_var) | 142 os.environ.pop(env_var) |
115 | 143 |
116 global _UNIVERSE | 144 global _UNIVERSE |
117 _UNIVERSE = universe | 145 _UNIVERSE = universe |
118 | 146 |
119 expect_tests.main('recipe_simulation_test', GenerateTests, | 147 expect_tests.main('recipe_simulation_test', GenerateTests, |
120 cover_omit=cover_omit(), args=args) | 148 cover_omit=cover_omit(), args=args) |
OLD | NEW |