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

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

Issue 2933473002: [context] Split "env" values and prefixes. (Closed)
Patch Set: comments Created 3 years, 6 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
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 26 matching lines...) Expand all
37 37
38 prev_ignore = os.environ.pop(requests_ssl.ENV_VAR_IGNORE, '0') 38 prev_ignore = os.environ.pop(requests_ssl.ENV_VAR_IGNORE, '0')
39 os.environ[requests_ssl.ENV_VAR_IGNORE] = '1' 39 os.environ[requests_ssl.ENV_VAR_IGNORE] = '1'
40 os.environ['RANDOM_MULTILINE_ENV'] = 'foo\nbar\nbaz\n' 40 os.environ['RANDOM_MULTILINE_ENV'] = 'foo\nbar\nbaz\n'
41 try: 41 try:
42 return ( 42 return (
43 ['python', script_path] + eng_args + ['run', recipe] + proplist) 43 ['python', script_path] + eng_args + ['run', recipe] + proplist)
44 finally: 44 finally:
45 os.environ[requests_ssl.ENV_VAR_IGNORE] = prev_ignore 45 os.environ[requests_ssl.ENV_VAR_IGNORE] = prev_ignore
46 46
47 def _test_recipe(self, recipe, properties=None): 47 def _test_recipe(self, recipe, properties=None, env=None):
48 proc = subprocess.Popen( 48 proc = subprocess.Popen(
49 self._run_cmd(recipe, properties), 49 self._run_cmd(recipe, properties),
50 stdout=subprocess.PIPE, 50 stdout=subprocess.PIPE,
51 stderr=subprocess.STDOUT) 51 stderr=subprocess.STDOUT,
52 env=env)
52 stdout = proc.communicate() 53 stdout = proc.communicate()
53 self.assertEqual(0, proc.returncode, '%d != %d when testing %s:\n%s' % ( 54 self.assertEqual(0, proc.returncode, '%d != %d when testing %s:\n%s' % (
54 0, proc.returncode, recipe, stdout)) 55 0, proc.returncode, recipe, stdout))
55 56
56 def test_examples(self): 57 def test_examples(self):
58 env = os.environ.copy()
59
60 # Set the "RECIPE_ENGINE_CONTEXT_TEST" enviornment variable to a known
61 # value, "default". This is used by the "context:tests/env" recipe module
62 # as a basis for runtime tests.
63 env['RECIPE_ENGINE_CONTEXT_TEST'] = 'default'
64
57 tests = [ 65 tests = [
66 ['context:examples/full'],
67 ['context:tests/env'],
58 ['step:examples/full'], 68 ['step:examples/full'],
59 ['path:examples/full'], 69 ['path:examples/full'],
60 ['raw_io:examples/full'], 70 ['raw_io:examples/full'],
61 ['python:examples/full'], 71 ['python:examples/full'],
62 ['json:examples/full'], 72 ['json:examples/full'],
63 ['uuid:examples/full'], 73 ['uuid:examples/full'],
64 ['file:examples/copy'], 74 ['file:examples/copy'],
65 ['file:examples/copytree'], 75 ['file:examples/copytree'],
66 76
67 ['engine_tests/depend_on/top', {'to_pass': 42}], 77 ['engine_tests/depend_on/top', {'to_pass': 42}],
68 ['engine_tests/functools_partial'], 78 ['engine_tests/functools_partial'],
69 ] 79 ]
70 for test in tests: 80 for test in tests:
71 self._test_recipe(*test) 81 self._test_recipe(*test, env=env)
72 82
73 def test_bad_subprocess(self): 83 def test_bad_subprocess(self):
74 now = time.time() 84 now = time.time()
75 self._test_recipe('engine_tests/bad_subprocess') 85 self._test_recipe('engine_tests/bad_subprocess')
76 after = time.time() 86 after = time.time()
77 87
78 # Test has a daemon that holds on to stdout for 30s, but the daemon's parent 88 # Test has a daemon that holds on to stdout for 30s, but the daemon's parent
79 # process (e.g. the one that recipe engine actually runs) quits immediately. 89 # process (e.g. the one that recipe engine actually runs) quits immediately.
80 # If this takes longer than 5 seconds to run, we consider it failed. 90 # If this takes longer than 5 seconds to run, we consider it failed.
81 self.assertLess(after - now, 5) 91 self.assertLess(after - now, 5)
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 u'foo', 270 u'foo',
261 u'bar', 271 u'bar',
262 u'baz', 272 u'baz',
263 ], 273 ],
264 }) 274 })
265 275
266 276
267 if __name__ == '__main__': 277 if __name__ == '__main__':
268 unittest.TestCase.maxDiff = None 278 unittest.TestCase.maxDiff = None
269 unittest.main() 279 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698