| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| 11 import unittest | 11 import unittest |
| 12 import time | 12 import time |
| 13 | 13 |
| 14 import test_env | 14 import test_env |
| 15 from test_env import BASE_DIR | 15 from test_env import BASE_DIR |
| 16 | 16 |
| 17 import recipe_engine.run | 17 import recipe_engine.run |
| 18 import recipe_engine.simulation_test as simulation_test |
| 18 import recipe_engine.step_runner | 19 import recipe_engine.step_runner |
| 19 from recipe_engine import recipe_test_api | 20 from recipe_engine import recipe_test_api |
| 20 import mock | 21 import mock |
| 21 | 22 |
| 22 class RunTest(unittest.TestCase): | 23 class RunTest(unittest.TestCase): |
| 23 def _run_cmd(self, recipe, properties=None): | 24 def _run_cmd(self, recipe, properties=None): |
| 24 script_path = os.path.join(BASE_DIR, 'recipes.py') | 25 script_path = os.path.join(BASE_DIR, 'recipes.py') |
| 25 | 26 |
| 26 if properties: | 27 if properties: |
| 27 proplist = [ '%s=%s' % (k, json.dumps(v)) | 28 proplist = [ '%s=%s' % (k, json.dumps(v)) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 with recipe_engine.stream.NoopStreamEngine() as stream_engine: | 133 with recipe_engine.stream.NoopStreamEngine() as stream_engine: |
| 133 properties = {} | 134 properties = {} |
| 134 | 135 |
| 135 test_data = recipe_engine.recipe_test_api.TestData() | 136 test_data = recipe_engine.recipe_test_api.TestData() |
| 136 test_data.expect_exception('SomeException') | 137 test_data.expect_exception('SomeException') |
| 137 | 138 |
| 138 api = mock.Mock() | 139 api = mock.Mock() |
| 139 api._engine = mock.Mock() | 140 api._engine = mock.Mock() |
| 140 api._engine.properties = properties | 141 api._engine.properties = properties |
| 141 | 142 |
| 143 annotator = simulation_test.SimulationAnnotatorStreamEngine() |
| 142 engine = recipe_engine.run.RecipeEngine( | 144 engine = recipe_engine.run.RecipeEngine( |
| 143 recipe_engine.step_runner.SimulationStepRunner( | 145 recipe_engine.step_runner.SimulationStepRunner( |
| 144 stream_engine, test_data), | 146 stream_engine, test_data, annotator), |
| 145 properties, | 147 properties, |
| 146 None) | 148 None) |
| 147 | 149 |
| 148 class FakeScript(object): | 150 class FakeScript(object): |
| 149 def run(self, _, __): | 151 def run(self, _, __): |
| 150 return None | 152 return None |
| 151 | 153 |
| 152 with self.assertRaises(AssertionError): | 154 with self.assertRaises(AssertionError): |
| 153 engine.run(FakeScript(), api) | 155 engine.run(FakeScript(), api) |
| 154 | 156 |
| 155 def test_subannotations(self): | 157 def test_subannotations(self): |
| 156 proc = subprocess.Popen( | 158 proc = subprocess.Popen( |
| 157 self._run_cmd('engine_tests/subannotations'), | 159 self._run_cmd('engine_tests/subannotations'), |
| 158 stdout=subprocess.PIPE, | 160 stdout=subprocess.PIPE, |
| 159 stderr=subprocess.PIPE) | 161 stderr=subprocess.PIPE) |
| 160 stdout, _ = proc.communicate() | 162 stdout, _ = proc.communicate() |
| 161 self.assertRegexpMatches(stdout, r'(?m)^!@@@BUILD_STEP@steppy@@@$') | 163 self.assertRegexpMatches(stdout, r'(?m)^!@@@BUILD_STEP@steppy@@@$') |
| 162 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$') | 164 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$') |
| 163 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the | 165 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the |
| 164 # state. | 166 # state. |
| 165 self.assertRegexpMatches(stdout, | 167 self.assertRegexpMatches(stdout, |
| 166 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$') | 168 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$') |
| 167 | 169 |
| 168 | 170 |
| 169 if __name__ == '__main__': | 171 if __name__ == '__main__': |
| 170 unittest.TestCase.maxDiff = None | 172 unittest.TestCase.maxDiff = None |
| 171 unittest.main() | 173 unittest.main() |
| OLD | NEW |