summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cmd_line.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2009-11-15 07:30:34 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2009-11-15 07:30:34 (GMT)
commit49868cb686954e57a6ab6bfea2cefeefb86305b1 (patch)
tree4e26a0452fac75a8a25ad6825729eab8ec2d0cf3 /Lib/test/test_cmd_line.py
parent51200277b23fd9faca5f03dae127221e9b67e7f1 (diff)
downloadcpython-49868cb686954e57a6ab6bfea2cefeefb86305b1.zip
cpython-49868cb686954e57a6ab6bfea2cefeefb86305b1.tar.gz
cpython-49868cb686954e57a6ab6bfea2cefeefb86305b1.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_cmd_line.py')
-rw-r--r--Lib/test/test_cmd_line.py32
1 files changed, 7 insertions, 25 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 09945f7..424d19b 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -5,34 +5,16 @@
import os
import test.test_support, unittest
import sys
-import subprocess
-
-def _spawn_python(*args):
- cmd_line = [sys.executable, '-E']
- cmd_line.extend(args)
- return subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-
-def _kill_python(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()
- return data
+from test.script_helper import spawn_python, kill_python, python_exit_code
+
class CmdLineTest(unittest.TestCase):
def start_python(self, *args):
- p = _spawn_python(*args)
- return _kill_python(p)
+ p = spawn_python(*args)
+ return kill_python(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)
@@ -85,10 +67,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('Timer\n')
p.stdin.write('exit()\n')
- data = _kill_python(p)
+ data = kill_python(p)
self.assertTrue(data.startswith('1 loop'))
self.assertTrue('__main__.Timer' in data)