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

Side by Side Diff: scripts/slave/unittests/recipes_test.py

Issue 187203005: Minor cleanup of some recipe framework code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Rietveld >_< Created 6 years, 9 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
« no previous file with comments | « scripts/slave/recipe_util.py ('k') | scripts/tools/show_me_the_modules.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2013 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 test coverage for individual recipes. 6 """Provides test coverage for individual recipes.
7 7
8 Recipe tests are located in ../recipes_test/*.py. 8 Recipe tests are located in ../recipes_test/*.py.
9 9
10 Each py file's splitext'd name is expected to match a recipe in ../recipes/*.py. 10 Each py file's splitext'd name is expected to match a recipe in ../recipes/*.py.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 root, name = os.path.split(recipe_path) 77 root, name = os.path.split(recipe_path)
78 name = os.path.splitext(name)[0] 78 name = os.path.splitext(name)[0]
79 expect_path = os.path.join(root, '%s.expected' % name) 79 expect_path = os.path.join(root, '%s.expected' % name)
80 if not os.path.isdir(expect_path): 80 if not os.path.isdir(expect_path):
81 os.makedirs(expect_path) 81 os.makedirs(expect_path)
82 return os.path.join(expect_path, test_name+'.json') 82 return os.path.join(expect_path, test_name+'.json')
83 83
84 84
85 def exec_test_file(recipe_name): 85 def exec_test_file(recipe_name):
86 with cover(): 86 with cover():
87 recipe = recipe_loader.LoadRecipe(recipe_name) 87 recipe = recipe_loader.load_recipe(recipe_name)
88 try: 88 try:
89 test_api = recipe_loader.CreateTestApi(recipe.DEPS) 89 test_api = recipe_loader.create_test_api(recipe.DEPS)
90 gen = recipe.GenTests(test_api) 90 gen = recipe.GenTests(test_api)
91 except Exception, e: 91 except Exception, e:
92 print "Caught exception while processing %s: %s" % (recipe_name, e) 92 print "Caught exception while processing %s: %s" % (recipe_name, e)
93 raise 93 raise
94 try: 94 try:
95 while True: 95 while True:
96 with cover(): 96 with cover():
97 test_data = next(gen) 97 test_data = next(gen)
98 yield test_data 98 yield test_data
99 except StopIteration: 99 except StopIteration:
100 pass 100 pass
101 except: 101 except:
102 print 'Exception while processing "%s"!' % recipe_name 102 print 'Exception while processing "%s"!' % recipe_name
103 raise 103 raise
104 104
105 105
106 def execute_test_case(test_data, recipe_path, recipe_name): 106 def execute_test_case(test_data, recipe_path, recipe_name):
107 try: 107 try:
108 props = test_data.properties 108 props = test_data.properties
109 props['recipe'] = recipe_name 109 props['recipe'] = recipe_name
110 110
111 stream = annotator.StructuredAnnotationStream(stream=open(os.devnull, 'w')) 111 stream = annotator.StructuredAnnotationStream(stream=open(os.devnull, 'w'))
112 112
113 def api(*args, **kwargs): 113 def api(*args, **kwargs):
114 return recipe_loader.CreateRecipeApi(test_data=test_data, *args, **kwargs) 114 return recipe_loader.create_recipe_api(
115 test_data=test_data, *args, **kwargs)
115 116
116 with cover(): 117 with cover():
117 recipe_config_types.ResetTostringFns() 118 recipe_config_types.ResetTostringFns()
118 step_data = annotated_run.run_steps( 119 step_data = annotated_run.run_steps(
119 stream, props, props, api, test_data).steps_ran.values() 120 stream, props, props, api, test_data).steps_ran.values()
120 return [s.step for s in step_data] 121 return [s.step for s in step_data]
121 except: 122 except:
122 print 'Exception while processing test case: "%s"!' % test_data.name 123 print 'Exception while processing test case: "%s"!' % test_data.name
123 raise 124 raise
124 125
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 retcode = retcode or 2 224 retcode = retcode or 2
224 225
225 if training: 226 if training:
226 test_env.print_coverage_warning() 227 test_env.print_coverage_warning()
227 228
228 return retcode 229 return retcode
229 230
230 231
231 if __name__ == '__main__': 232 if __name__ == '__main__':
232 sys.exit(main(sys.argv)) 233 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « scripts/slave/recipe_util.py ('k') | scripts/tools/show_me_the_modules.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698