| 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 unittest | 10 import unittest |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 self.assertRegexpMatches(stdout, '(?m)^@@@STEP_EXCEPTION@@@$') | 104 self.assertRegexpMatches(stdout, '(?m)^@@@STEP_EXCEPTION@@@$') |
| 105 self.assertRegexpMatches(stdout, 'OSError') | 105 self.assertRegexpMatches(stdout, 'OSError') |
| 106 self.assertEqual(1, subp.returncode, stdout) | 106 self.assertEqual(1, subp.returncode, stdout) |
| 107 finally: | 107 finally: |
| 108 if os.path.exists(path): | 108 if os.path.exists(path): |
| 109 os.unlink(path) | 109 os.unlink(path) |
| 110 | 110 |
| 111 def test_trigger(self): | 111 def test_trigger(self): |
| 112 subp = subprocess.Popen( | 112 subp = subprocess.Popen( |
| 113 self._run_cmd('engine_tests/trigger'), | 113 self._run_cmd('step:tests/trigger'), |
| 114 stdout=subprocess.PIPE) | 114 stdout=subprocess.PIPE) |
| 115 stdout, _ = subp.communicate() | 115 stdout, _ = subp.communicate() |
| 116 self.assertEqual(0, subp.returncode) | 116 self.assertEqual(0, subp.returncode) |
| 117 m = re.compile(r'^@@@STEP_TRIGGER@(.*)@@@$', re.MULTILINE).search(stdout) | 117 m = re.compile(r'^@@@STEP_TRIGGER@(.*)@@@$', re.MULTILINE).search(stdout) |
| 118 self.assertTrue(m) | 118 self.assertTrue(m) |
| 119 blob = m.group(1) | 119 blob = m.group(1) |
| 120 json.loads(blob) # Raises an exception if the blob is not valid json. | 120 json.loads(blob) # Raises an exception if the blob is not valid json. |
| 121 | 121 |
| 122 def test_trigger_no_such_command(self): | 122 def test_trigger_no_such_command(self): |
| 123 """Tests that trigger still happens even if running the command fails.""" | 123 """Tests that trigger still happens even if running the command fails.""" |
| 124 subp = subprocess.Popen( | 124 subp = subprocess.Popen( |
| 125 self._run_cmd( | 125 self._run_cmd( |
| 126 'engine_tests/trigger', properties={'command': ['na-huh']}), | 126 'step:tests/trigger', properties={'command': ['na-huh']}), |
| 127 stdout=subprocess.PIPE) | 127 stdout=subprocess.PIPE) |
| 128 stdout, _ = subp.communicate() | 128 stdout, _ = subp.communicate() |
| 129 self.assertRegexpMatches(stdout, r'(?m)^@@@STEP_TRIGGER@(.*)@@@$') | 129 self.assertRegexpMatches(stdout, r'(?m)^@@@STEP_TRIGGER@(.*)@@@$') |
| 130 self.assertEqual(255, subp.returncode) | 130 self.assertEqual(255, subp.returncode) |
| 131 | 131 |
| 132 def test_trigger_no_such_command_new(self): | 132 def test_trigger_no_such_command_new(self): |
| 133 """Tests that trigger still happens even if running the command fails.""" | 133 """Tests that trigger still happens even if running the command fails.""" |
| 134 _, path = tempfile.mkstemp('args_pb') | 134 _, path = tempfile.mkstemp('args_pb') |
| 135 with open(path, 'w') as f: | 135 with open(path, 'w') as f: |
| 136 json.dump({ | 136 json.dump({ |
| 137 'engine_flags': { | 137 'engine_flags': { |
| 138 'use_result_proto': True | 138 'use_result_proto': True |
| 139 } | 139 } |
| 140 }, f) | 140 }, f) |
| 141 | 141 |
| 142 try: | 142 try: |
| 143 subp = subprocess.Popen( | 143 subp = subprocess.Popen( |
| 144 self._run_cmd( | 144 self._run_cmd( |
| 145 'engine_tests/trigger', properties={'command': ['na-huh']}, | 145 'step:tests/trigger', properties={'command': ['na-huh']}, |
| 146 engine_args=['--operational-args-path', path]), | 146 engine_args=['--operational-args-path', path]), |
| 147 stdout=subprocess.PIPE) | 147 stdout=subprocess.PIPE) |
| 148 stdout, _ = subp.communicate() | 148 stdout, _ = subp.communicate() |
| 149 | 149 |
| 150 self.assertRegexpMatches(stdout, r'(?m)^@@@STEP_TRIGGER@(.*)@@@$') | 150 self.assertRegexpMatches(stdout, r'(?m)^@@@STEP_TRIGGER@(.*)@@@$') |
| 151 self.assertEqual(1, subp.returncode) | 151 self.assertEqual(1, subp.returncode) |
| 152 finally: | 152 finally: |
| 153 if os.path.exists(path): | 153 if os.path.exists(path): |
| 154 os.unlink(path) | 154 os.unlink(path) |
| 155 | 155 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 181 'bash', '-c', '/bin/echo %s' % quoted]) | 181 'bash', '-c', '/bin/echo %s' % quoted]) |
| 182 self.assertEqual(bash_output.decode('utf-8'), s + '\n') | 182 self.assertEqual(bash_output.decode('utf-8'), s + '\n') |
| 183 | 183 |
| 184 # zsh is untested because zsh isn't provisioned on our bots. (luqui) | 184 # zsh is untested because zsh isn't provisioned on our bots. (luqui) |
| 185 # zsh_output = subprocess.check_output([ | 185 # zsh_output = subprocess.check_output([ |
| 186 # 'zsh', '-c', '/bin/echo %s' % quoted]) | 186 # 'zsh', '-c', '/bin/echo %s' % quoted]) |
| 187 # self.assertEqual(zsh_output.decode('utf-8'), s + '\n') | 187 # self.assertEqual(zsh_output.decode('utf-8'), s + '\n') |
| 188 | 188 |
| 189 def test_subannotations(self): | 189 def test_subannotations(self): |
| 190 proc = subprocess.Popen( | 190 proc = subprocess.Popen( |
| 191 self._run_cmd('engine_tests/subannotations'), | 191 self._run_cmd('step:tests/subannotations'), |
| 192 stdout=subprocess.PIPE, | 192 stdout=subprocess.PIPE, |
| 193 stderr=subprocess.PIPE) | 193 stderr=subprocess.PIPE) |
| 194 stdout, _ = proc.communicate() | 194 stdout, _ = proc.communicate() |
| 195 self.assertRegexpMatches(stdout, r'(?m)^!@@@BUILD_STEP@steppy@@@$') | 195 self.assertRegexpMatches(stdout, r'(?m)^!@@@BUILD_STEP@steppy@@@$') |
| 196 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$') | 196 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$') |
| 197 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the | 197 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the |
| 198 # state. | 198 # state. |
| 199 self.assertRegexpMatches(stdout, | 199 self.assertRegexpMatches(stdout, |
| 200 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$') | 200 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$') |
| 201 | 201 |
| 202 | 202 |
| 203 if __name__ == '__main__': | 203 if __name__ == '__main__': |
| 204 unittest.TestCase.maxDiff = None | 204 unittest.TestCase.maxDiff = None |
| 205 unittest.main() | 205 unittest.main() |
| OLD | NEW |