diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2009-11-16 06:49:25 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2009-11-16 06:49:25 (GMT) |
commit | 260bd3e5578008682f009530faa615f74c6bcf82 (patch) | |
tree | 3dc3aab1aeb7fbe13350eba4c4437c371b4faffe /Lib/test/test_cmd_line.py | |
parent | 36fbb730a72c0a00a2c2dc44d49b9b7af5a86174 (diff) | |
download | cpython-260bd3e5578008682f009530faa615f74c6bcf82.zip cpython-260bd3e5578008682f009530faa615f74c6bcf82.tar.gz cpython-260bd3e5578008682f009530faa615f74c6bcf82.tar.bz2 |
Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76286 | nick.coghlan | 2009-11-15 17:30:34 +1000 (Sun, 15 Nov 2009) | 1 line
Issue #6816: expose the zipfile and directory execution mechanism to Python code via the runpy module. Also consolidated some script execution functionality in the test harness into a helper module and removed some implementation details from the runpy module documentation.
........
r76321 | nick.coghlan | 2009-11-16 13:55:51 +1000 (Mon, 16 Nov 2009) | 1 line
Account for another cache when hunting ref leaks
........
r76322 | nick.coghlan | 2009-11-16 13:57:32 +1000 (Mon, 16 Nov 2009) | 1 line
Allow for backslashes in file paths passed to the regex engine
........
Diffstat (limited to 'Lib/test/test_cmd_line.py')
-rw-r--r-- | Lib/test/test_cmd_line.py | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index b4a1f9f..852a7aa 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -6,44 +6,41 @@ import os import test.support, unittest import os import sys -import subprocess +from test.script_helper import spawn_python, kill_python, python_exit_code + +# XXX (ncoghlan): there are assorted gratuitous inconsistencies between the +# support code in the Py3k version and the 2.x version that unnecessarily +# complicate test suite merges. See issue 7331 -def _spawn_python(*args): +# spawn_python normally enforces use of -E to avoid environmental effects +# but one test checks PYTHONPATH behaviour explicitly +# XXX (ncoghlan): Give script_helper.spawn_python an option to switch +# off the -E flag that is normally inserted automatically +import subprocess +def _spawn_python_with_env(*args): cmd_line = [sys.executable] - # When testing -S, we need PYTHONPATH to work (see test_site_flag()) - if '-S' not in args: - cmd_line.append('-E') cmd_line.extend(args) return subprocess.Popen(cmd_line, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) -def _kill_python(p): - return _kill_python_and_exit_code(p)[0] +# XXX (ncoghlan): Move to script_helper and make consistent with run_python def _kill_python_and_exit_code(p): - p.stdin.close() - data = p.stdout.read() - p.stdout.close() - # try to cleanup the child so we don't appear to leak when running - # with regrtest -R. This should be a no-op on Windows. - subprocess._cleanup() + data = kill_python(p) returncode = p.wait() return data, returncode class CmdLineTest(unittest.TestCase): def start_python(self, *args): - return self.start_python_and_exit_code(*args)[0] + p = spawn_python(*args) + return kill_python(p) def start_python_and_exit_code(self, *args): - p = _spawn_python(*args) + p = spawn_python(*args) return _kill_python_and_exit_code(p) def exit_code(self, *args): - cmd_line = [sys.executable, '-E'] - cmd_line.extend(args) - with open(os.devnull, 'w') as devnull: - return subprocess.call(cmd_line, stdout=devnull, - stderr=subprocess.STDOUT) + return python_exit_code(*args) def test_directories(self): self.assertNotEqual(self.exit_code('.'), 0) @@ -107,10 +104,10 @@ class CmdLineTest(unittest.TestCase): # -m and -i need to play well together # Runs the timeit module and checks the __main__ # namespace has been populated appropriately - p = _spawn_python('-i', '-m', 'timeit', '-n', '1') + p = spawn_python('-i', '-m', 'timeit', '-n', '1') p.stdin.write(b'Timer\n') p.stdin.write(b'exit()\n') - data = _kill_python(p) + data = kill_python(p) self.assertTrue(data.find(b'1 loop') != -1) self.assertTrue(data.find(b'__main__.Timer') != -1) @@ -154,7 +151,7 @@ class CmdLineTest(unittest.TestCase): def test_unbuffered_input(self): # sys.stdin still works with '-u' code = ("import sys; sys.stdout.write(sys.stdin.read(1))") - p = _spawn_python('-u', '-c', code) + p = spawn_python('-u', '-c', code) p.stdin.write(b'x') p.stdin.flush() data, rc = _kill_python_and_exit_code(p) @@ -166,7 +163,8 @@ class CmdLineTest(unittest.TestCase): path1 = "ABCDE" * 100 path2 = "FGHIJ" * 100 env['PYTHONPATH'] = path1 + os.pathsep + path2 - p = _spawn_python('-S', '-c', 'import sys; print(sys.path)') + p = _spawn_python_with_env('-S', '-c', + 'import sys; print(sys.path)') stdout, _ = p.communicate() self.assertTrue(path1.encode('ascii') in stdout) self.assertTrue(path2.encode('ascii') in stdout) |