diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-11-09 21:33:55 +0000 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-11-09 21:33:55 +0000 |
commit | 9bc35682de4911ea917f1016cc5fd67d3d1be97e (patch) | |
tree | 47d1727afe761d9f0e6a6985ba7f7e6152570b5c /Lib/test/script_helper.py | |
parent | e912f5ab7ada996e5d464c9a4f99638188744c18 (diff) | |
download | cpython-git-9bc35682de4911ea917f1016cc5fd67d3d1be97e.tar.gz |
Use script_helper in one more test
Diffstat (limited to 'Lib/test/script_helper.py')
-rw-r--r-- | Lib/test/script_helper.py | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/Lib/test/script_helper.py b/Lib/test/script_helper.py index 4cadcf7196..095895ee50 100644 --- a/Lib/test/script_helper.py +++ b/Lib/test/script_helper.py @@ -15,11 +15,17 @@ from imp import source_from_cache from test.support import make_legacy_pyc # Executing the interpreter in a subprocess -def _assert_python(expected_success, *args): - cmd_line = [sys.executable, '-E'] +def _assert_python(expected_success, *args, **env_vars): + cmd_line = [sys.executable] + if env_vars: + env = env_vars + else: + env = os.environ + cmd_line.append('-E') cmd_line.extend(args) p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE, + env=env) try: out, err = p.communicate() finally: @@ -33,11 +39,19 @@ def _assert_python(expected_success, *args): "stderr follows:\n%s" % (rc, err.decode('ascii', 'ignore'))) return rc, out, err -def assert_python_ok(*args): - return _assert_python(True, *args) +def assert_python_ok(*args, **env_vars): + """ + Assert that running the interpreter with `args` and optional environment + variables `env_vars` is ok and return a (return code, stdout, stderr) tuple. + """ + return _assert_python(True, *args, **env_vars) -def assert_python_failure(*args): - return _assert_python(False, *args) +def assert_python_failure(*args, **env_vars): + """ + Assert that running the interpreter with `args` and optional environment + variables `env_vars` fails and return a (return code, stdout, stderr) tuple. + """ + return _assert_python(False, *args, **env_vars) def spawn_python(*args): cmd_line = [sys.executable, '-E'] |