@@ -747,31 +747,36 @@ def test_pipesizes(self):
747747 @unittest .skipUnless (fcntl and hasattr (fcntl , 'F_GETPIPE_SZ' ),
748748 'fcntl.F_GETPIPE_SZ required for test.' )
749749 def test_pipesize_default (self ):
750- p = subprocess .Popen (
750+ proc = subprocess .Popen (
751751 [sys .executable , "-c" ,
752752 'import sys; sys.stdin.read(); sys.stdout.write("out"); '
753753 'sys.stderr.write("error!")' ],
754754 stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
755755 stderr = subprocess .PIPE , pipesize = - 1 )
756- try :
757- fp_r , fp_w = os . pipe ()
756+
757+ with proc :
758758 try :
759- default_pipesize = fcntl .fcntl (fp_w , fcntl .F_GETPIPE_SZ )
760- for fifo in [p .stdin , p .stdout , p .stderr ]:
761- self .assertEqual (
762- fcntl .fcntl (fifo .fileno (), fcntl .F_GETPIPE_SZ ),
763- default_pipesize )
759+ fp_r , fp_w = os .pipe ()
760+ try :
761+ default_read_pipesize = fcntl .fcntl (fp_r , fcntl .F_GETPIPE_SZ )
762+ default_write_pipesize = fcntl .fcntl (fp_w , fcntl .F_GETPIPE_SZ )
763+ finally :
764+ os .close (fp_r )
765+ os .close (fp_w )
766+
767+ self .assertEqual (
768+ fcntl .fcntl (proc .stdin .fileno (), fcntl .F_GETPIPE_SZ ),
769+ default_read_pipesize )
770+ self .assertEqual (
771+ fcntl .fcntl (proc .stdout .fileno (), fcntl .F_GETPIPE_SZ ),
772+ default_write_pipesize )
773+ self .assertEqual (
774+ fcntl .fcntl (proc .stderr .fileno (), fcntl .F_GETPIPE_SZ ),
775+ default_write_pipesize )
776+ # On other platforms we cannot test the pipe size (yet). But above
777+ # code using pipesize=-1 should not crash.
764778 finally :
765- os .close (fp_r )
766- os .close (fp_w )
767- # On other platforms we cannot test the pipe size (yet). But above
768- # code using pipesize=-1 should not crash.
769- p .stdin .close ()
770- p .stdout .close ()
771- p .stderr .close ()
772- finally :
773- p .kill ()
774- p .wait ()
779+ proc .kill ()
775780
776781 def test_env (self ):
777782 newenv = os .environ .copy ()
0 commit comments