| 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 logging | 7 import logging |
| 8 import re | 8 import re |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| 11 | 11 |
| 12 from .third_party import expect_tests | 12 from .third_party import expect_tests |
| 13 | 13 |
| 14 # This variable must be set in the dynamic scope of the functions in this file. | 14 # This variable must be set in the dynamic scope of the functions in this file. |
| 15 # We do this instead of passing because the threading system of expect tests | 15 # We do this instead of passing because the threading system of expect tests |
| 16 # doesn't know how to serialize it. | 16 # doesn't know how to serialize it. |
| 17 _UNIVERSE = None | 17 _UNIVERSE = None |
| 18 | 18 |
| 19 def RunRecipe(test_data): | 19 def RunRecipe(test_data): |
| 20 from . import config_types | 20 from . import config_types |
| 21 from . import loader | 21 from . import loader |
| 22 from . import run | 22 from . import run |
| 23 from . import step_runner | 23 from . import step_runner |
| 24 from . import stream | 24 from . import stream |
| 25 | 25 |
| 26 config_types.ResetTostringFns() | 26 config_types.ResetTostringFns() |
| 27 stream_engine = stream.StreamEngineInvariants() | 27 with stream.StreamEngineInvariants() as stream_engine: |
| 28 step_runner = step_runner.SimulationStepRunner(stream_engine, test_data) | 28 step_runner = step_runner.SimulationStepRunner(stream_engine, test_data) |
| 29 | 29 |
| 30 engine = run.RecipeEngine(step_runner, test_data.properties, _UNIVERSE) | 30 engine = run.RecipeEngine(step_runner, test_data.properties, _UNIVERSE) |
| 31 recipe_script = _UNIVERSE.load_recipe(test_data.properties['recipe']) | 31 recipe_script = _UNIVERSE.load_recipe(test_data.properties['recipe']) |
| 32 api = loader.create_recipe_api(recipe_script.LOADED_DEPS, engine, test_data) | 32 api = loader.create_recipe_api(recipe_script.LOADED_DEPS, engine, test_data) |
| 33 result = engine.run(recipe_script, api) | 33 result = engine.run(recipe_script, api) |
| 34 | 34 |
| 35 # Don't include tracebacks in expectations because they are too sensitive to | 35 # Don't include tracebacks in expectations because they are too sensitive to |
| 36 # change. | 36 # change. |
| 37 result.result.pop('traceback', None) | 37 result.result.pop('traceback', None) |
| 38 | 38 |
| 39 return expect_tests.Result(step_runner.steps_ran + [result.result]) | 39 return expect_tests.Result(step_runner.steps_ran + [result.result]) |
| 40 | 40 |
| 41 | 41 |
| 42 def test_gen_coverage(): | 42 def test_gen_coverage(): |
| 43 cover = [] | 43 cover = [] |
| 44 | 44 |
| 45 for path in _UNIVERSE.recipe_dirs: | 45 for path in _UNIVERSE.recipe_dirs: |
| 46 cover.append(os.path.join(path, '*')) | 46 cover.append(os.path.join(path, '*')) |
| 47 | 47 |
| 48 for path in _UNIVERSE.module_dirs: | 48 for path in _UNIVERSE.module_dirs: |
| 49 cover.append(os.path.join(path, '*', 'example.py')) | 49 cover.append(os.path.join(path, '*', 'example.py')) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 'TESTING_SLAVENAME']: | 110 'TESTING_SLAVENAME']: |
| 111 if env_var in os.environ: | 111 if env_var in os.environ: |
| 112 logging.warn("Ignoring %s environment variable." % env_var) | 112 logging.warn("Ignoring %s environment variable." % env_var) |
| 113 os.environ.pop(env_var) | 113 os.environ.pop(env_var) |
| 114 | 114 |
| 115 global _UNIVERSE | 115 global _UNIVERSE |
| 116 _UNIVERSE = universe | 116 _UNIVERSE = universe |
| 117 | 117 |
| 118 expect_tests.main('recipe_simulation_test', GenerateTests, | 118 expect_tests.main('recipe_simulation_test', GenerateTests, |
| 119 cover_omit=cover_omit(), args=args) | 119 cover_omit=cover_omit(), args=args) |
| OLD | NEW |