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

Side by Side Diff: recipe_engine/test.py

Issue 2850543002: Fix recipes.py test train when on-disk expectation files are invalid (Closed)
Patch Set: Created 3 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
« no previous file with comments | « no previous file | unittests/test_test.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 # Copyright 2017 The LUCI Authors. All rights reserved. 1 # Copyright 2017 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 from __future__ import print_function 5 from __future__ import print_function
6 6
7 import argparse 7 import argparse
8 import bdb 8 import bdb
9 import cStringIO 9 import cStringIO
10 import contextlib 10 import contextlib
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 print('Uncaught exception. Entering post mortem debugging') 200 print('Uncaught exception. Entering post mortem debugging')
201 print('Running \'cont\' or \'step\' will restart the program') 201 print('Running \'cont\' or \'step\' will restart the program')
202 t = sys.exc_info()[2] 202 t = sys.exc_info()[2]
203 debugger.interaction(None, t) 203 debugger.interaction(None, t)
204 204
205 205
206 def run_test(test_description, debug=False, train=False): 206 def run_test(test_description, debug=False, train=False):
207 """Runs a test. Returns TestResults object.""" 207 """Runs a test. Returns TestResults object."""
208 expected = None 208 expected = None
209 if os.path.exists(test_description.expectation_path): 209 if os.path.exists(test_description.expectation_path):
210 with open(test_description.expectation_path) as f: 210 try:
211 # TODO(phajdan.jr): why do we need to re-encode golden data files? 211 with open(test_description.expectation_path) as f:
212 expected = re_encode(json.load(f)) 212 # TODO(phajdan.jr): why do we need to re-encode golden data files?
213 expected = re_encode(json.load(f))
214 except Exception:
215 if train:
216 # Ignore errors when training; we're going to overwrite the file anyway.
217 expected = None
218 else:
219 raise
213 220
214 break_funcs = [ 221 break_funcs = [
215 _UNIVERSE_VIEW.load_recipe(test_description.recipe_name).run_steps, 222 _UNIVERSE_VIEW.load_recipe(test_description.recipe_name).run_steps,
216 ] 223 ]
217 224
218 with maybe_debug(break_funcs, debug): 225 with maybe_debug(break_funcs, debug):
219 actual, failed_checks, coverage_data = run_recipe( 226 actual, failed_checks, coverage_data = run_recipe(
220 test_description.recipe_name, test_description.test_name, 227 test_description.recipe_name, test_description.test_name,
221 test_description.covers, 228 test_description.covers,
222 enable_coverage=(not debug)) 229 enable_coverage=(not debug))
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 Returns: 910 Returns:
904 Exit code 911 Exit code
905 """ 912 """
906 global _UNIVERSE_VIEW 913 global _UNIVERSE_VIEW
907 _UNIVERSE_VIEW = universe_view 914 _UNIVERSE_VIEW = universe_view
908 global _ENGINE_FLAGS 915 global _ENGINE_FLAGS
909 _ENGINE_FLAGS = engine_flags 916 _ENGINE_FLAGS = engine_flags
910 917
911 args = parse_args(raw_args) 918 args = parse_args(raw_args)
912 return args.func(args) 919 return args.func(args)
OLDNEW
« no previous file with comments | « no previous file | unittests/test_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698