diff options
author | Tim Golden <mail@timgolden.me.uk> | 2010-08-08 16:18:45 (GMT) |
---|---|---|
committer | Tim Golden <mail@timgolden.me.uk> | 2010-08-08 16:18:45 (GMT) |
commit | 6fe8c41e8ff4d87fd6bb1bc9ae67d0f49b5073f4 (patch) | |
tree | 033d2a36ca09bc5ed11b5a3f88464dd097cf0ea6 /Lib/test | |
parent | e677ecfccf8a0a54a4e099a3c08cac8a271e9d65 (diff) | |
download | cpython-6fe8c41e8ff4d87fd6bb1bc9ae67d0f49b5073f4.zip cpython-6fe8c41e8ff4d87fd6bb1bc9ae67d0f49b5073f4.tar.gz cpython-6fe8c41e8ff4d87fd6bb1bc9ae67d0f49b5073f4.tar.bz2 |
Issue #2304: Add additional quotes when using cmd shell on Windows. Original patch from Gabriel Genellina
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_subprocess.py | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 15ca1975..ccb7a69 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -872,12 +872,54 @@ class HelperFunctionTests(unittest.TestCase): self.assertEqual([(256, 999), (666,), (666,)], record_calls) +@unittest.skipUnless(mswindows, "mswindows only") +class CommandsWithSpaces (BaseTestCase): + + def setUp(self): + super(CommandsWithSpaces, self).setUp() + f, fname = mkstemp(".py", "te st") + self.fname = fname.lower () + os.write(f, b"import sys;" + b"sys.stdout.write('%d %s' % (len(sys.argv), [a.lower () for a in sys.argv]))" + ) + os.close(f) + + def tearDown(self): + os.remove(self.fname) + super(CommandsWithSpaces, self).tearDown() + + def with_spaces(self, *args, **kwargs): + kwargs['stdout'] = subprocess.PIPE + p = subprocess.Popen(*args, **kwargs) + self.assertEqual( + p.stdout.read ().decode("mbcs"), + "2 [%r, 'ab cd']" % self.fname + ) + + def test_shell_string_with_spaces(self): + # call() function with string argument with spaces on Windows + self.with_spaces('"%s" "%s"' % (self.fname, "ab cd"), shell=1) + + def test_shell_sequence_with_spaces(self): + # call() function with sequence argument with spaces on Windows + self.with_spaces([self.fname, "ab cd"], shell=1) + + def test_noshell_string_with_spaces(self): + # call() function with string argument with spaces on Windows + self.with_spaces('"%s" "%s" "%s"' % (sys.executable, self.fname, + "ab cd")) + + def test_noshell_sequence_with_spaces(self): + # call() function with sequence argument with spaces on Windows + self.with_spaces([sys.executable, self.fname, "ab cd"]) + def test_main(): unit_tests = (ProcessTestCase, POSIXProcessTestCase, Win32ProcessTestCase, ProcessTestCaseNoPoll, - HelperFunctionTests) + HelperFunctionTests, + CommandsWithSpaces) test_support.run_unittest(*unit_tests) test_support.reap_children() |