Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: recipe_engine/unittests/run_test.py

Issue 2798053003: introduce recipe_exception in result.proto (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « recipe_engine/step_runner.py ('k') | recipes.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 os.environ['RANDOM_MULTILINE_ENV'] = 'foo\nbar\nbaz\n' 38 os.environ['RANDOM_MULTILINE_ENV'] = 'foo\nbar\nbaz\n'
39 try: 39 try:
40 return ( 40 return (
41 ['python', script_path] + eng_args + ['run', recipe] + proplist) 41 ['python', script_path] + eng_args + ['run', recipe] + proplist)
42 finally: 42 finally:
43 os.environ[requests_ssl.ENV_VAR_IGNORE] = prev_ignore 43 os.environ[requests_ssl.ENV_VAR_IGNORE] = prev_ignore
44 44
45 def _test_recipe(self, recipe, properties=None): 45 def _test_recipe(self, recipe, properties=None):
46 proc = subprocess.Popen( 46 proc = subprocess.Popen(
47 self._run_cmd(recipe, properties), stdout=subprocess.PIPE) 47 self._run_cmd(recipe, properties), stdout=subprocess.PIPE)
48 proc.communicate() 48 stdout, stderr = proc.communicate()
49 self.assertEqual(0, proc.returncode, '%d != %d when testing %s' % ( 49 self.assertEqual(
50 0, proc.returncode, recipe)) 50 0, proc.returncode,
51 ('%d != %d when testing %s\nstdout: %s\nstderr: %s' % (
52 0, proc.returncode, recipe, stdout, stderr)))
51 53
52 def test_examples(self): 54 def test_examples(self):
53 tests = [ 55 tests = [
54 ['step:example'], 56 ['step:example'],
55 ['path:example'], 57 ['path:example'],
56 ['raw_io:example'], 58 ['raw_io:example'],
57 ['python:example'], 59 ['python:example'],
58 ['json:example'], 60 ['json:example'],
59 ['uuid:example'], 61 ['uuid:example'],
60 62
61 ['engine_tests/depend_on/top', {'to_pass': 42}], 63 ['engine_tests/depend_on/top', {'to_pass': 42}],
62 ['engine_tests/functools_partial'], 64 ['engine_tests/functools_partial'],
63 ] 65 ]
64 for test in tests: 66 for test in tests:
65 self._test_recipe(*test) 67 self._test_recipe(*test)
66 68
67 def test_bad_subprocess(self): 69 def test_bad_subprocess(self):
68 now = time.time() 70 now = time.time()
69 self._test_recipe('engine_tests/bad_subprocess') 71 self._test_recipe('engine_tests/bad_subprocess')
70 after = time.time() 72 after = time.time()
71 73
72 # Test has a daemon that holds on to stdout for 30s, but the daemon's parent 74 # Test has a daemon that holds on to stdout for 30s, but the daemon's parent
73 # process (e.g. the one that recipe engine actually runs) quits immediately. 75 # process (e.g. the one that recipe engine actually runs) quits immediately.
74 # If this takes longer than 5 seconds to run, we consider it failed. 76 # If this takes longer than 5 seconds to run, we consider it failed.
75 self.assertLess(after - now, 5) 77 self.assertLess(after - now, 5)
76 78
77
78 def test_nonexistent_command(self): 79 def test_nonexistent_command(self):
79 subp = subprocess.Popen( 80 subp = subprocess.Popen(
80 self._run_cmd('engine_tests/nonexistent_command'), 81 self._run_cmd('engine_tests/nonexistent_command'),
81 stdout=subprocess.PIPE) 82 stdout=subprocess.PIPE)
82 stdout, _ = subp.communicate() 83 stdout, _ = subp.communicate()
83 self.assertRegexpMatches(stdout, '(?m)^@@@STEP_EXCEPTION@@@$') 84 self.assertRegexpMatches(stdout, '(?m)^@@@STEP_EXCEPTION@@@$')
84 self.assertRegexpMatches(stdout, 'OSError') 85 self.assertRegexpMatches(stdout, 'OSError')
85 self.assertEqual(255, subp.returncode, stdout) 86 self.assertEqual(255, subp.returncode, stdout)
86 87
87 def test_nonexistent_command_new(self): 88 def test_nonexistent_command_new(self):
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$') 197 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$')
197 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the 198 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the
198 # state. 199 # state.
199 self.assertRegexpMatches(stdout, 200 self.assertRegexpMatches(stdout,
200 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$') 201 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$')
201 202
202 203
203 if __name__ == '__main__': 204 if __name__ == '__main__':
204 unittest.TestCase.maxDiff = None 205 unittest.TestCase.maxDiff = None
205 unittest.main() 206 unittest.main()
OLDNEW
« no previous file with comments | « recipe_engine/step_runner.py ('k') | recipes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698