| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Provides simulator test coverage for individual recipes.""" | 6 """Provides simulator test coverage for individual recipes.""" |
| 7 | 7 |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 | 10 |
| 11 # Importing for side effects on sys.path? Yes... yes we are :( | 11 # Importing for side effects on sys.path? Yes... yes we are :( |
| 12 import test_env # pylint: disable=W0611,W0403 | 12 import test_env # pylint: disable=W0611,W0403 |
| 13 | 13 |
| 14 from common import annotator | 14 from common import annotator |
| 15 from slave import annotated_run | 15 from slave import annotated_run |
| 16 from slave import recipe_config_types | 16 from slave import recipe_config_types |
| 17 from slave import recipe_loader | 17 from slave import recipe_loader |
| 18 from slave import recipe_util | 18 from slave import recipe_util |
| 19 | 19 |
| 20 import expect_tests # pylint: disable=W0403 | 20 import expect_tests # pylint: disable=W0403 |
| 21 | 21 |
| 22 | 22 |
| 23 UNIVERSE = recipe_loader.RecipeUniverse() |
| 24 |
| 25 |
| 23 def RunRecipe(test_data): | 26 def RunRecipe(test_data): |
| 24 stream = annotator.StructuredAnnotationStream(stream=open(os.devnull, 'w')) | 27 stream = annotator.StructuredAnnotationStream(stream=open(os.devnull, 'w')) |
| 25 recipe_config_types.ResetTostringFns() | 28 recipe_config_types.ResetTostringFns() |
| 26 # TODO(iannucci): Only pass test_data once. | 29 # TODO(iannucci): Only pass test_data once. |
| 27 result = annotated_run.run_steps(stream, test_data.properties, | 30 result = annotated_run.run_steps(stream, test_data.properties, |
| 28 test_data.properties, test_data) | 31 test_data.properties, |
| 32 UNIVERSE, |
| 33 test_data) |
| 29 | 34 |
| 30 return expect_tests.Result(list(result.steps_ran.values())) | 35 return expect_tests.Result(list(result.steps_ran.values())) |
| 31 | 36 |
| 32 | 37 |
| 33 def test_gen_coverage(): | 38 def test_gen_coverage(): |
| 34 return ( | 39 return ( |
| 35 [os.path.join(x, '*') for x in recipe_util.RECIPE_DIRS()] + | 40 [os.path.join(x, '*') for x in recipe_util.RECIPE_DIRS()] + |
| 36 [os.path.join(x, '*', 'example.py') for x in recipe_util.MODULE_DIRS()] + | 41 [os.path.join(x, '*', 'example.py') for x in recipe_util.MODULE_DIRS()] + |
| 37 [os.path.join(x, '*', 'test_api.py') for x in recipe_util.MODULE_DIRS()] | 42 [os.path.join(x, '*', 'test_api.py') for x in recipe_util.MODULE_DIRS()] |
| 38 ) | 43 ) |
| 39 | 44 |
| 45 |
| 40 @expect_tests.covers(test_gen_coverage) | 46 @expect_tests.covers(test_gen_coverage) |
| 41 def GenerateTests(): | 47 def GenerateTests(): |
| 42 cover_mods = [] | 48 cover_mods = [] |
| 43 for mod_dir_base in recipe_util.MODULE_DIRS(): | 49 for mod_dir_base in recipe_util.MODULE_DIRS(): |
| 44 if os.path.isdir(mod_dir_base): | 50 if os.path.isdir(mod_dir_base): |
| 45 cover_mods.append(os.path.join(mod_dir_base, '*', '*.py')) | 51 cover_mods.append(os.path.join(mod_dir_base, '*', '*.py')) |
| 46 | 52 |
| 47 for recipe_path, recipe_name in recipe_loader.loop_over_recipes(): | 53 for recipe_path, recipe_name in recipe_loader.loop_over_recipes(): |
| 48 recipe = recipe_loader.load_recipe(recipe_name) | 54 recipe = UNIVERSE.load_recipe(recipe_name) |
| 49 test_api = recipe_loader.create_test_api(recipe.DEPS) | 55 test_api = recipe_loader.create_test_api(recipe.LOADED_DEPS, UNIVERSE) |
| 50 | 56 |
| 51 covers = cover_mods + [recipe_path] | 57 covers = cover_mods + [recipe_path] |
| 52 | 58 |
| 53 for test_data in recipe.GenTests(test_api): | 59 for test_data in recipe.GenTests(test_api): |
| 54 root, name = os.path.split(recipe_path) | 60 root, name = os.path.split(recipe_path) |
| 55 name = os.path.splitext(name)[0] | 61 name = os.path.splitext(name)[0] |
| 56 expect_path = os.path.join(root, '%s.expected' % name) | 62 expect_path = os.path.join(root, '%s.expected' % name) |
| 57 | 63 |
| 58 test_data.properties['recipe'] = recipe_name.replace('\\', '/') | 64 test_data.properties['recipe'] = recipe_name.replace('\\', '/') |
| 59 yield expect_tests.Test( | 65 yield expect_tests.Test( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 70 # annotated_run.py has different behavior when these environment variables | 76 # annotated_run.py has different behavior when these environment variables |
| 71 # are set, so unset to make simulation tests environment-invariant. | 77 # are set, so unset to make simulation tests environment-invariant. |
| 72 for env_var in ['TESTING_MASTER_HOST', | 78 for env_var in ['TESTING_MASTER_HOST', |
| 73 'TESTING_MASTER', | 79 'TESTING_MASTER', |
| 74 'TESTING_SLAVENAME']: | 80 'TESTING_SLAVENAME']: |
| 75 if env_var in os.environ: | 81 if env_var in os.environ: |
| 76 logging.warn("Ignoring %s environment variable." % env_var) | 82 logging.warn("Ignoring %s environment variable." % env_var) |
| 77 os.environ.pop(env_var) | 83 os.environ.pop(env_var) |
| 78 | 84 |
| 79 expect_tests.main('recipe_simulation_test', GenerateTests) | 85 expect_tests.main('recipe_simulation_test', GenerateTests) |
| OLD | NEW |