| 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 requests_ssl | 20 from recipe_engine import requests_ssl |
| 20 from recipe_engine import recipe_test_api | 21 from recipe_engine import recipe_test_api |
| 21 import mock | 22 import mock |
| 22 | 23 |
| 23 class RunTest(unittest.TestCase): | 24 class RunTest(unittest.TestCase): |
| 24 def _run_cmd(self, recipe, properties=None): | 25 def _run_cmd(self, recipe, properties=None): |
| 25 script_path = os.path.join(BASE_DIR, 'recipes.py') | 26 script_path = os.path.join(BASE_DIR, 'recipes.py') |
| 26 | 27 |
| 27 if properties: | 28 if properties: |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 with recipe_engine.stream.NoopStreamEngine() as stream_engine: | 139 with recipe_engine.stream.NoopStreamEngine() as stream_engine: |
| 139 properties = {} | 140 properties = {} |
| 140 | 141 |
| 141 test_data = recipe_engine.recipe_test_api.TestData() | 142 test_data = recipe_engine.recipe_test_api.TestData() |
| 142 test_data.expect_exception('SomeException') | 143 test_data.expect_exception('SomeException') |
| 143 | 144 |
| 144 api = mock.Mock() | 145 api = mock.Mock() |
| 145 api._engine = mock.Mock() | 146 api._engine = mock.Mock() |
| 146 api._engine.properties = properties | 147 api._engine.properties = properties |
| 147 | 148 |
| 149 annotator = simulation_test.SimulationAnnotatorStreamEngine() |
| 148 engine = recipe_engine.run.RecipeEngine( | 150 engine = recipe_engine.run.RecipeEngine( |
| 149 recipe_engine.step_runner.SimulationStepRunner( | 151 recipe_engine.step_runner.SimulationStepRunner( |
| 150 stream_engine, test_data), | 152 stream_engine, test_data, annotator), |
| 151 properties, | 153 properties, |
| 152 None) | 154 None) |
| 153 | 155 |
| 154 class FakeScript(object): | 156 class FakeScript(object): |
| 155 def run(self, _, __): | 157 def run(self, _, __): |
| 156 return None | 158 return None |
| 157 | 159 |
| 158 with self.assertRaises(AssertionError): | 160 with self.assertRaises(AssertionError): |
| 159 engine.run(FakeScript(), api) | 161 engine.run(FakeScript(), api) |
| 160 | 162 |
| 161 def test_subannotations(self): | 163 def test_subannotations(self): |
| 162 proc = subprocess.Popen( | 164 proc = subprocess.Popen( |
| 163 self._run_cmd('engine_tests/subannotations'), | 165 self._run_cmd('engine_tests/subannotations'), |
| 164 stdout=subprocess.PIPE, | 166 stdout=subprocess.PIPE, |
| 165 stderr=subprocess.PIPE) | 167 stderr=subprocess.PIPE) |
| 166 stdout, _ = proc.communicate() | 168 stdout, _ = proc.communicate() |
| 167 self.assertRegexpMatches(stdout, r'(?m)^!@@@BUILD_STEP@steppy@@@$') | 169 self.assertRegexpMatches(stdout, r'(?m)^!@@@BUILD_STEP@steppy@@@$') |
| 168 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$') | 170 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$') |
| 169 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the | 171 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the |
| 170 # state. | 172 # state. |
| 171 self.assertRegexpMatches(stdout, | 173 self.assertRegexpMatches(stdout, |
| 172 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$') | 174 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$') |
| 173 | 175 |
| 174 | 176 |
| 175 if __name__ == '__main__': | 177 if __name__ == '__main__': |
| 176 unittest.TestCase.maxDiff = None | 178 unittest.TestCase.maxDiff = None |
| 177 unittest.main() | 179 unittest.main() |
| OLD | NEW |