diff options
Diffstat (limited to 'Lib/test/test_cmd_line.py')
-rw-r--r-- | Lib/test/test_cmd_line.py | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index cb1bc9ff..441df09 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -3,18 +3,25 @@ import test.test_support, unittest import sys import subprocess +def _spawn_python(*args): + cmd_line = [sys.executable] + 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 + class CmdLineTest(unittest.TestCase): - def start_python(self, cmd_line): - cmd = '"%s" %s' % (sys.executable, cmd_line) - p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - 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 + def start_python(self, *args): + p = _spawn_python(*args) + return _kill_python(p) def exit_code(self, *args): cmd_line = [sys.executable] @@ -72,6 +79,17 @@ class CmdLineTest(unittest.TestCase): self.exit_code('-m', 'timeit', '-n', '1'), 0) + def test_run_module_bug1764407(self): + # -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.stdin.write('Timer\n') + p.stdin.write('exit()\n') + data = _kill_python(p) + self.assertTrue(data.find(b'1 loop') != -1) + self.assertTrue(data.find(b'__main__.Timer') != -1) + def test_run_code(self): # Test expected operation of the '-c' switch # Switch needs an argument |