Chromium Code Reviews| 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.simulation_test as simulation_test |
| 19 import recipe_engine.step_runner | 19 import recipe_engine.step_runner |
| 20 import recipe_engine.util | |
| 20 from recipe_engine import requests_ssl | 21 from recipe_engine import requests_ssl |
| 21 from recipe_engine import recipe_test_api | 22 from recipe_engine import recipe_test_api |
| 22 import mock | 23 import mock |
| 23 | 24 |
| 24 class RunTest(unittest.TestCase): | 25 class RunTest(unittest.TestCase): |
| 25 def _run_cmd(self, recipe, properties=None): | 26 def _run_cmd(self, recipe, properties=None): |
| 26 script_path = os.path.join(BASE_DIR, 'recipes.py') | 27 script_path = os.path.join(BASE_DIR, 'recipes.py') |
| 27 | 28 |
| 28 if properties: | 29 if properties: |
| 29 proplist = [ '%s=%s' % (k, json.dumps(v)) | 30 proplist = [ '%s=%s' % (k, json.dumps(v)) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 'bash', '-c', '/bin/echo %s' % quoted]) | 131 'bash', '-c', '/bin/echo %s' % quoted]) |
| 131 self.assertEqual(bash_output.decode('utf-8'), s + '\n') | 132 self.assertEqual(bash_output.decode('utf-8'), s + '\n') |
| 132 | 133 |
| 133 # zsh is untested because zsh isn't provisioned on our bots. (luqui) | 134 # zsh is untested because zsh isn't provisioned on our bots. (luqui) |
| 134 # zsh_output = subprocess.check_output([ | 135 # zsh_output = subprocess.check_output([ |
| 135 # 'zsh', '-c', '/bin/echo %s' % quoted]) | 136 # 'zsh', '-c', '/bin/echo %s' % quoted]) |
| 136 # self.assertEqual(zsh_output.decode('utf-8'), s + '\n') | 137 # self.assertEqual(zsh_output.decode('utf-8'), s + '\n') |
| 137 | 138 |
| 138 def test_run_unconsumed(self): | 139 def test_run_unconsumed(self): |
| 139 with recipe_engine.stream.NoopStreamEngine() as stream_engine: | 140 with recipe_engine.stream.NoopStreamEngine() as stream_engine: |
| 140 properties = {} | 141 rt = recipe_engine.run.Runtime( |
| 142 {}, | |
| 143 platform=recipe_engine.util.Platform( | |
| 144 name='linux', arch='testmachine', bits=64)) | |
| 141 | 145 |
| 142 test_data = recipe_engine.recipe_test_api.TestData() | 146 test_data = recipe_engine.recipe_test_api.TestData() |
| 143 test_data.expect_exception('SomeException') | 147 test_data.expect_exception('SomeException') |
| 144 | 148 |
| 145 api = mock.Mock() | 149 api = mock.Mock() |
| 146 api._engine = mock.Mock() | |
|
dnj
2016/10/13 01:08:23
This was actually vestigial from before "_engine"
| |
| 147 api._engine.properties = properties | |
| 148 | |
| 149 annotator = simulation_test.SimulationAnnotatorStreamEngine() | 150 annotator = simulation_test.SimulationAnnotatorStreamEngine() |
| 150 engine = recipe_engine.run.RecipeEngine( | 151 engine = recipe_engine.run.RecipeEngine( |
| 151 recipe_engine.step_runner.SimulationStepRunner( | 152 recipe_engine.step_runner.SimulationStepRunner( |
| 152 stream_engine, test_data, annotator), | 153 stream_engine, test_data, annotator), |
| 153 properties, | 154 rt, |
| 154 None) | 155 None) |
| 155 | 156 |
| 156 class FakeScript(object): | 157 class FakeScript(object): |
| 157 def run(self, _, __): | 158 def run(self, _, __): |
| 158 return None | 159 return None |
| 159 | 160 |
| 160 with self.assertRaises(AssertionError): | 161 with self.assertRaises(AssertionError): |
| 161 engine.run(FakeScript(), api, properties) | 162 engine.run(FakeScript(), api, rt.properties) |
| 162 | 163 |
| 163 def test_subannotations(self): | 164 def test_subannotations(self): |
| 164 proc = subprocess.Popen( | 165 proc = subprocess.Popen( |
| 165 self._run_cmd('engine_tests/subannotations'), | 166 self._run_cmd('engine_tests/subannotations'), |
| 166 stdout=subprocess.PIPE, | 167 stdout=subprocess.PIPE, |
| 167 stderr=subprocess.PIPE) | 168 stderr=subprocess.PIPE) |
| 168 stdout, _ = proc.communicate() | 169 stdout, _ = proc.communicate() |
| 169 self.assertRegexpMatches(stdout, r'(?m)^!@@@BUILD_STEP@steppy@@@$') | 170 self.assertRegexpMatches(stdout, r'(?m)^!@@@BUILD_STEP@steppy@@@$') |
| 170 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$') | 171 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$') |
| 171 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the | 172 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the |
| 172 # state. | 173 # state. |
| 173 self.assertRegexpMatches(stdout, | 174 self.assertRegexpMatches(stdout, |
| 174 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$') | 175 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$') |
| 175 | 176 |
| 176 | 177 |
| 177 if __name__ == '__main__': | 178 if __name__ == '__main__': |
| 178 unittest.TestCase.maxDiff = None | 179 unittest.TestCase.maxDiff = None |
| 179 unittest.main() | 180 unittest.main() |
| OLD | NEW |