| OLD | NEW |
| 1 # Copyright 2014-2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2014-2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # 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 . 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 .third_party import annotator | 20 from .third_party import annotator |
| 21 from . import main | 21 from . import run |
| 22 from . import config_types | 22 from . import config_types |
| 23 | 23 |
| 24 stream = annotator.StructuredAnnotationStream(stream=open(os.devnull, 'w')) | 24 stream = annotator.StructuredAnnotationStream(stream=open(os.devnull, 'w')) |
| 25 config_types.ResetTostringFns() | 25 config_types.ResetTostringFns() |
| 26 result = main.run_steps( | 26 result = run.run_steps( |
| 27 test_data.properties, stream, _UNIVERSE, test_data) | 27 test_data.properties, stream, _UNIVERSE, test_data) |
| 28 | 28 |
| 29 return expect_tests.Result(list(result.steps_ran.values())) | 29 return expect_tests.Result(list(result.steps_ran.values())) |
| 30 | 30 |
| 31 | 31 |
| 32 def test_gen_coverage(): | 32 def test_gen_coverage(): |
| 33 return ( | 33 return ( |
| 34 [os.path.join(x, '*') for x in _UNIVERSE.recipe_dirs] + | 34 [os.path.join(x, '*') for x in _UNIVERSE.recipe_dirs] + |
| 35 [os.path.join(x, '*', 'example.py') for x in _UNIVERSE.module_dirs] + | 35 [os.path.join(x, '*', 'example.py') for x in _UNIVERSE.module_dirs] + |
| 36 [os.path.join(x, '*', 'test_api.py') for x in _UNIVERSE.module_dirs] | 36 [os.path.join(x, '*', 'test_api.py') for x in _UNIVERSE.module_dirs] |
| (...skipping 30 matching lines...) Expand all Loading... |
| 67 yield expect_tests.Test( | 67 yield expect_tests.Test( |
| 68 '%s.%s' % (recipe_name, test_data.name), | 68 '%s.%s' % (recipe_name, test_data.name), |
| 69 expect_tests.FuncCall(RunRecipe, test_data), | 69 expect_tests.FuncCall(RunRecipe, test_data), |
| 70 expect_dir=expect_path, | 70 expect_dir=expect_path, |
| 71 expect_base=test_data.name, | 71 expect_base=test_data.name, |
| 72 covers=covers, | 72 covers=covers, |
| 73 break_funcs=(recipe.RunSteps,) | 73 break_funcs=(recipe.RunSteps,) |
| 74 ) | 74 ) |
| 75 | 75 |
| 76 | 76 |
| 77 def main(universe): | 77 def main(package_deps, args=None): |
| 78 """Runs simulation tests on a given repo of recipes. | 78 """Runs simulation tests on a given repo of recipes. |
| 79 | 79 |
| 80 Args: | 80 Args: |
| 81 universe: a RecipeUniverse to operate on. | 81 package_deps: a PackageDeps object to operate on |
| 82 args: command line arguments to expect_tests |
| 82 Returns: | 83 Returns: |
| 83 Doesn't -- exits with a status code | 84 Doesn't -- exits with a status code |
| 84 """ | 85 """ |
| 86 from . import loader |
| 87 from . import package |
| 85 | 88 |
| 86 # annotated_run has different behavior when these environment variables | 89 # annotated_run has different behavior when these environment variables |
| 87 # are set, so unset to make simulation tests environment-invariant. | 90 # are set, so unset to make simulation tests environment-invariant. |
| 88 for env_var in ['TESTING_MASTER_HOST', | 91 for env_var in ['TESTING_MASTER_HOST', |
| 89 'TESTING_MASTER', | 92 'TESTING_MASTER', |
| 90 'TESTING_SLAVENAME']: | 93 'TESTING_SLAVENAME']: |
| 91 if env_var in os.environ: | 94 if env_var in os.environ: |
| 92 logging.warn("Ignoring %s environment variable." % env_var) | 95 logging.warn("Ignoring %s environment variable." % env_var) |
| 93 os.environ.pop(env_var) | 96 os.environ.pop(env_var) |
| 94 | 97 |
| 95 global _UNIVERSE | 98 global _UNIVERSE |
| 96 _UNIVERSE = universe | 99 _UNIVERSE = loader.RecipeUniverse(package_deps) |
| 100 |
| 97 expect_tests.main('recipe_simulation_test', GenerateTests, | 101 expect_tests.main('recipe_simulation_test', GenerateTests, |
| 98 cover_omit=cover_omit()) | 102 cover_omit=cover_omit(), args=args) |
| OLD | NEW |