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