Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 if name.endswith('_test'): | 112 if name.endswith('_test'): |
| 113 ret[name[:-len('_test')]] = value | 113 ret[name[:-len('_test')]] = value |
| 114 return ret | 114 return ret |
| 115 | 115 |
| 116 | 116 |
| 117 def execute_test_case(test_fn, recipe_path): | 117 def execute_test_case(test_fn, recipe_path): |
| 118 test_data = test_fn(TestAPI()) | 118 test_data = test_fn(TestAPI()) |
| 119 bp = test_data.get('build_properties', {}) | 119 bp = test_data.get('build_properties', {}) |
| 120 fp = test_data.get('factory_properties', {}) | 120 fp = test_data.get('factory_properties', {}) |
| 121 td = test_data.get('test_data', {}) | 121 td = test_data.get('test_data', {}) |
| 122 me = test_data.get('mock_path_exists', []) | |
| 122 fp['recipe'] = os.path.basename(os.path.splitext(recipe_path)[0]) | 123 fp['recipe'] = os.path.basename(os.path.splitext(recipe_path)[0]) |
| 123 | 124 |
| 124 stream = annotator.StructuredAnnotationStream(stream=open(os.devnull, 'w')) | 125 stream = annotator.StructuredAnnotationStream(stream=open(os.devnull, 'w')) |
| 125 with cover(): | 126 with cover(): |
| 126 with recipe_util.mock_paths(): | 127 with recipe_util.mock_paths(mock_path_exists=me): |
|
iannucci
2013/05/20 19:41:38
Ah, I guess this is implicitly an empty list here
| |
| 127 step_data = annotated_run.run_steps(stream, bp, fp, td).steps_ran.values() | 128 step_data = annotated_run.run_steps(stream, bp, fp, td).steps_ran.values() |
| 128 return [s.step for s in step_data] | 129 return [s.step for s in step_data] |
| 129 | 130 |
| 130 | 131 |
| 131 def train_from_tests(recipe_path): | 132 def train_from_tests(recipe_path): |
| 132 if not has_test(recipe_path): | 133 if not has_test(recipe_path): |
| 133 print 'FATAL: Recipe %s has NO tests!' % recipe_path | 134 print 'FATAL: Recipe %s has NO tests!' % recipe_path |
| 134 return False | 135 return False |
| 135 | 136 |
| 136 for path in glob(expected_for(recipe_path, '*')): | 137 for path in glob(expected_for(recipe_path, '*')): |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 total_covered = COVERAGE.report() | 241 total_covered = COVERAGE.report() |
| 241 if total_covered != 100.0: | 242 if total_covered != 100.0: |
| 242 print 'FATAL: Recipes are not at 100% coverage.' | 243 print 'FATAL: Recipes are not at 100% coverage.' |
| 243 retcode = retcode or 2 | 244 retcode = retcode or 2 |
| 244 | 245 |
| 245 return retcode | 246 return retcode |
| 246 | 247 |
| 247 | 248 |
| 248 if __name__ == '__main__': | 249 if __name__ == '__main__': |
| 249 sys.exit(main(sys.argv)) | 250 sys.exit(main(sys.argv)) |
| OLD | NEW |