@@ -366,22 +366,28 @@ def test_communicate(self):
366366 self .assertEqual (stdout , b"banana" )
367367 self .assertStderrEqual (stderr , b"pineapple" )
368368
369- # This test is Linux specific for simplicity to at least have
370- # some coverage. It is not a platform specific bug.
371- @unittest .skipUnless (os .path .isdir ('/proc/%d/fd' % os .getpid ()),
372- "Linux specific" )
373369 # Test for the fd leak reported in http://bugs.python.org/issue2791.
374370 def test_communicate_pipe_fd_leak (self ):
375- fd_directory = '/proc/%d/fd' % os .getpid ()
376- num_fds_before_popen = len (os .listdir (fd_directory ))
377- p = subprocess .Popen ([sys .executable , "-c" , "print()" ],
378- stdout = subprocess .PIPE )
379- p .communicate ()
380- num_fds_after_communicate = len (os .listdir (fd_directory ))
381- del p
382- num_fds_after_destruction = len (os .listdir (fd_directory ))
383- self .assertEqual (num_fds_before_popen , num_fds_after_destruction )
384- self .assertEqual (num_fds_before_popen , num_fds_after_communicate )
371+ for stdin_pipe in (False , True ):
372+ for stdout_pipe in (False , True ):
373+ for stderr_pipe in (False , True ):
374+ options = {}
375+ if stdin_pipe :
376+ options ['stdin' ] = subprocess .PIPE
377+ if stdout_pipe :
378+ options ['stdout' ] = subprocess .PIPE
379+ if stderr_pipe :
380+ options ['stderr' ] = subprocess .PIPE
381+ if not options :
382+ continue
383+ p = subprocess .Popen ((sys .executable , "-c" , "pass" ), ** options )
384+ p .communicate ()
385+ if p .stdin is not None :
386+ self .assertTrue (p .stdin .closed )
387+ if p .stdout is not None :
388+ self .assertTrue (p .stdout .closed )
389+ if p .stderr is not None :
390+ self .assertTrue (p .stderr .closed )
385391
386392 def test_communicate_returns (self ):
387393 # communicate() should return None if no redirection is active
0 commit comments