@@ -1015,6 +1015,7 @@ def test_terminate(self):
10151015 self ._kill_process ('terminate' )
10161016
10171017
1018+
10181019# The module says:
10191020# "NB This only works (and is only relevant) for UNIX."
10201021#
@@ -1041,6 +1042,46 @@ def test_getoutput(self):
10411042 if dir is not None :
10421043 os .rmdir (dir )
10431044
1045+ class CommandsWithSpaces (BaseTestCase ):
1046+
1047+ def setUp (self ):
1048+ super ().setUp ()
1049+ f , fname = mkstemp (".py" , "te st" )
1050+ self .fname = fname .lower ()
1051+ os .write (f , b"import sys;"
1052+ b"sys.stdout.write('%d %s' % (len(sys.argv), [a.lower () for a in sys.argv]))"
1053+ )
1054+ os .close (f )
1055+
1056+ def tearDown (self ):
1057+ os .remove (self .fname )
1058+ super ().tearDown ()
1059+
1060+ def with_spaces (self , * args , ** kwargs ):
1061+ kwargs ['stdout' ] = subprocess .PIPE
1062+ p = subprocess .Popen (* args , ** kwargs )
1063+ self .assertEqual (
1064+ p .stdout .read ().decode ("mbcs" ),
1065+ "2 [%r, 'ab cd']" % self .fname
1066+ )
1067+
1068+ def test_shell_string_with_spaces (self ):
1069+ # call() function with string argument with spaces on Windows
1070+ self .with_spaces ('"%s" "%s"' % (self .fname , "ab cd" ), shell = 1 )
1071+
1072+ def test_shell_sequence_with_spaces (self ):
1073+ # call() function with sequence argument with spaces on Windows
1074+ self .with_spaces ([self .fname , "ab cd" ], shell = 1 )
1075+
1076+ def test_noshell_string_with_spaces (self ):
1077+ # call() function with string argument with spaces on Windows
1078+ self .with_spaces ('"%s" "%s" "%s"' % (sys .executable , self .fname ,
1079+ "ab cd" ))
1080+
1081+ def test_noshell_sequence_with_spaces (self ):
1082+ # call() function with sequence argument with spaces on Windows
1083+ self .with_spaces ([sys .executable , self .fname , "ab cd" ])
1084+
10441085
10451086@unittest .skipUnless (getattr (subprocess , '_has_poll' , False ),
10461087 "poll system call not supported" )
@@ -1093,6 +1134,7 @@ def test_main():
10931134 Win32ProcessTestCase ,
10941135 ProcessTestCasePOSIXPurePython ,
10951136 CommandTests ,
1137+ CommandsWithSpaces ,
10961138 ProcessTestCaseNoPoll ,
10971139 HelperFunctionTests )
10981140
0 commit comments