| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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) |
| OLD | NEW |