summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2010-12-14 13:43:30 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2010-12-14 13:43:30 (GMT)
commit8edd99d0852c45f70b6abc851e6b326d4250cd33 (patch)
tree739c5f3039791b749228455076e6af2d89d71b8c /Lib/test
parent39f34aa1f3c1f02d72ec28d0d177834e22dfc89b (diff)
downloadcpython-8edd99d0852c45f70b6abc851e6b326d4250cd33.zip
cpython-8edd99d0852c45f70b6abc851e6b326d4250cd33.tar.gz
cpython-8edd99d0852c45f70b6abc851e6b326d4250cd33.tar.bz2
Issue #6559: fix the subprocess.Popen pass_fds implementation. Add a unittest.
Issue #7213: Change the close_fds default on Windows to better match the new default on POSIX. True when possible (False if stdin/stdout/stderr are supplied). Update the documentation to reflect all of the above.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_subprocess.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 74e7404..0804a13 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1042,6 +1042,37 @@ class POSIXProcessTestCase(BaseTestCase):
"Some fds were left open")
self.assertIn(1, remaining_fds, "Subprocess failed")
+ def test_pass_fds(self):
+ fd_status = support.findfile("fd_status.py", subdir="subprocessdata")
+
+ open_fds = set()
+
+ for x in range(5):
+ fds = os.pipe()
+ self.addCleanup(os.close, fds[0])
+ self.addCleanup(os.close, fds[1])
+ open_fds.update(fds)
+
+ for fd in open_fds:
+ p = subprocess.Popen([sys.executable, fd_status],
+ stdout=subprocess.PIPE, close_fds=True,
+ pass_fds=(fd, ))
+ output, ignored = p.communicate()
+
+ remaining_fds = set(map(int, output.split(b',')))
+ to_be_closed = open_fds - {fd}
+
+ self.assertIn(fd, remaining_fds, "fd to be passed not passed")
+ self.assertFalse(remaining_fds & to_be_closed,
+ "fd to be closed passed")
+
+ # pass_fds overrides close_fds with a warning.
+ with self.assertWarns(RuntimeWarning) as context:
+ self.assertFalse(subprocess.call(
+ [sys.executable, "-c", "import sys; sys.exit(0)"],
+ close_fds=False, pass_fds=(fd, )))
+ self.assertIn('overriding close_fds', str(context.warning))
+
@unittest.skipUnless(mswindows, "Windows specific tests")
class Win32ProcessTestCase(BaseTestCase):