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

Side by Side Diff: third_party/recipe_engine/recipe_simulation_test.py

Issue 1151423002: Move recipe engine to third_party/recipe_engine. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Copyright notices Created 5 years, 7 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 | Annotate | Revision Log
OLDNEW
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 re
9 import os 10 import os
11 import sys
10 12
11 # Importing for side effects on sys.path? Yes... yes we are :( 13 from . import recipe_util
12 import test_env # pylint: disable=W0611,W0403 14 from . import expect_tests # XXX pylint XXX: disable=W0403
iannucci 2015/05/27 02:03:27 ???? this looks fine or move expect_tests to thi
luqui 2015/05/28 21:47:38 Acknowledged.
13 15
14 from slave import recipe_util 16 # This variable must be set in the dynamic scope of the functions in this file.
15 17 # We do this instead of passing because the threading system of expect tests
16 import expect_tests # pylint: disable=W0403 18 # doesn't know how to serialize it.
17
18
19 _UNIVERSE = None 19 _UNIVERSE = None
iannucci 2015/05/27 02:03:27 probably should document that this is a RecipeLoad
luqui 2015/05/28 21:47:38 Done.
20 def get_universe():
21 from slave import recipe_loader
22 global _UNIVERSE
23 if _UNIVERSE is None:
24 _UNIVERSE = recipe_loader.RecipeUniverse()
25 return _UNIVERSE
26
27 20
28 def RunRecipe(test_data): 21 def RunRecipe(test_data):
29 from common import annotator 22 from .third_party import annotator
30 from slave import annotated_run 23 from . import annotated_run
31 from slave import recipe_config_types 24 from . import recipe_config_types
32 25
33 stream = annotator.StructuredAnnotationStream(stream=open(os.devnull, 'w')) 26 stream = annotator.StructuredAnnotationStream(stream=open(os.devnull, 'w'))
34 recipe_config_types.ResetTostringFns() 27 recipe_config_types.ResetTostringFns()
35 # TODO(iannucci): Only pass test_data once. 28 result = annotated_run.run_steps(
36 result = annotated_run.run_steps(stream, test_data.properties, 29 test_data.properties, stream, _UNIVERSE, test_data)
37 test_data.properties,
38 get_universe(),
39 test_data)
40 30
41 return expect_tests.Result(list(result.steps_ran.values())) 31 return expect_tests.Result(list(result.steps_ran.values()))
42 32
43 33
44 def test_gen_coverage(): 34 def test_gen_coverage():
45 return ( 35 return (
46 [os.path.join(x, '*') for x in recipe_util.RECIPE_DIRS()] + 36 [os.path.join(x, '*') for x in _UNIVERSE.recipe_dirs] +
47 [os.path.join(x, '*', 'example.py') for x in recipe_util.MODULE_DIRS()] + 37 [os.path.join(x, '*', 'example.py') for x in _UNIVERSE.module_dirs] +
48 [os.path.join(x, '*', 'test_api.py') for x in recipe_util.MODULE_DIRS()] + 38 [os.path.join(x, '*', 'test_api.py') for x in _UNIVERSE.module_dirs]
49 [os.path.join(os.path.dirname(recipe_util.__file__), 'recipe_api.py')]
iannucci 2015/05/27 02:03:27 lost this? but really!! we want tests for the eng
50 ) 39 )
51 40
41 def cover_omit():
42 omit = [ ]
43 for mod_dir_base in _UNIVERSE.module_dirs:
44 if os.path.isdir(mod_dir_base):
45 omit.append(os.path.join(mod_dir_base, '*', 'resources', '*'))
46 return omit
52 47
53 @expect_tests.covers(test_gen_coverage) 48 @expect_tests.covers(test_gen_coverage)
54 def GenerateTests(): 49 def GenerateTests():
55 from slave import recipe_loader 50 from . import recipe_loader
56 51
57 universe = get_universe() 52 cover_mods = [ ]
58 53 for mod_dir_base in _UNIVERSE.module_dirs:
59 cover_mods = [
60 os.path.join(os.path.dirname(recipe_util.__file__), 'recipe_api.py')
61 ]
62 for mod_dir_base in recipe_util.MODULE_DIRS():
63 if os.path.isdir(mod_dir_base): 54 if os.path.isdir(mod_dir_base):
64 cover_mods.append(os.path.join(mod_dir_base, '*', '*.py')) 55 cover_mods.append(os.path.join(mod_dir_base, '*', '*.py'))
65 56
66 for recipe_path, recipe_name in recipe_loader.loop_over_recipes(): 57 for recipe_path, recipe_name in _UNIVERSE.loop_over_recipes():
67 recipe = universe.load_recipe(recipe_name) 58 recipe = _UNIVERSE.load_recipe(recipe_name)
68 test_api = recipe_loader.create_test_api(recipe.LOADED_DEPS, universe) 59 test_api = recipe_loader.create_test_api(recipe.LOADED_DEPS, _UNIVERSE)
69 60
70 covers = cover_mods + [recipe_path] 61 covers = cover_mods + [recipe_path]
71 62
72 for test_data in recipe.GenTests(test_api): 63 for test_data in recipe.GenTests(test_api):
73 root, name = os.path.split(recipe_path) 64 root, name = os.path.split(recipe_path)
74 name = os.path.splitext(name)[0] 65 name = os.path.splitext(name)[0]
75 expect_path = os.path.join(root, '%s.expected' % name) 66 expect_path = os.path.join(root, '%s.expected' % name)
76 67
77 test_data.properties['recipe'] = recipe_name.replace('\\', '/') 68 test_data.properties['recipe'] = recipe_name.replace('\\', '/')
78 yield expect_tests.Test( 69 yield expect_tests.Test(
79 '%s.%s' % (recipe_name, test_data.name), 70 '%s.%s' % (recipe_name, test_data.name),
80 expect_tests.FuncCall(RunRecipe, test_data), 71 expect_tests.FuncCall(RunRecipe, test_data),
81 expect_dir=expect_path, 72 expect_dir=expect_path,
82 expect_base=test_data.name, 73 expect_base=test_data.name,
83 covers=covers, 74 covers=covers,
84 break_funcs=(recipe.GenSteps,) 75 break_funcs=(recipe.GenSteps,)
85 ) 76 )
86 77
87 78
88 if __name__ == '__main__': 79 def main(universe):
89 # annotated_run.py has different behavior when these environment variables 80 # annotated_run has different behavior when these environment variables
iannucci 2015/05/27 02:03:27 maybe assert universe is something that we can dea
luqui 2015/05/28 21:47:38 Added docs is all
90 # are set, so unset to make simulation tests environment-invariant. 81 # are set, so unset to make simulation tests environment-invariant.
91 for env_var in ['TESTING_MASTER_HOST', 82 for env_var in ['TESTING_MASTER_HOST',
92 'TESTING_MASTER', 83 'TESTING_MASTER',
93 'TESTING_SLAVENAME']: 84 'TESTING_SLAVENAME']:
94 if env_var in os.environ: 85 if env_var in os.environ:
95 logging.warn("Ignoring %s environment variable." % env_var) 86 logging.warn("Ignoring %s environment variable." % env_var)
96 os.environ.pop(env_var) 87 os.environ.pop(env_var)
97 88
98 expect_tests.main('recipe_simulation_test', GenerateTests) 89 global _UNIVERSE
90 _UNIVERSE = universe
91 expect_tests.main('recipe_simulation_test', GenerateTests,
92 cover_omit=cover_omit())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698