diff options
author | Tim Golden <mail@timgolden.me.uk> | 2010-08-11 14:20:40 (GMT) |
---|---|---|
committer | Tim Golden <mail@timgolden.me.uk> | 2010-08-11 14:20:40 (GMT) |
commit | 126c2960ca36f26730e28f41f66e62f0934d0575 (patch) | |
tree | af328b9e180100e7ea3d3eb31eaa95d590258ecb /Lib/test/test_subprocess.py | |
parent | 32cfedeb1c378d6acf8e39308831f826f614a204 (diff) | |
download | cpython-126c2960ca36f26730e28f41f66e62f0934d0575.zip cpython-126c2960ca36f26730e28f41f66e62f0934d0575.tar.gz cpython-126c2960ca36f26730e28f41f66e62f0934d0575.tar.bz2 |
#2304: fix incorporating Eric Smith's .format suggestion and tested on Ubuntu as well as Windows
Diffstat (limited to 'Lib/test/test_subprocess.py')
-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 95da107..27401da 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1087,6 +1087,47 @@ class HelperFunctionTests(unittest.TestCase): self.assertEqual([(256, 999), (666,), (666,)], record_calls) +@unittest.skipUnless(mswindows, "Windows-specific tests") +class CommandsWithSpaces (BaseTestCase): + + def setUp(self): + super().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().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, @@ -1094,7 +1135,8 @@ def test_main(): ProcessTestCasePOSIXPurePython, CommandTests, ProcessTestCaseNoPoll, - HelperFunctionTests) + HelperFunctionTests, + CommandsWithSpaces) support.run_unittest(*unit_tests) support.reap_children() |