MCPcopy Index your code
hub / github.com/python/cpython / test_pass_fds

Method test_pass_fds

Lib/test/test_subprocess.py:3147–3178  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3145 # descriptor is invalid, and read or write raise an error.
3146 @support.requires_mac_ver(10, 5)
3147 def test_pass_fds(self):
3148 fd_status = support.findfile("fd_status.py", subdir="subprocessdata")
3149
3150 open_fds = set()
3151
3152 for x in range(5):
3153 fds = os.pipe()
3154 self.addCleanup(os.close, fds[0])
3155 self.addCleanup(os.close, fds[1])
3156 os.set_inheritable(fds[0], True)
3157 os.set_inheritable(fds[1], True)
3158 open_fds.update(fds)
3159
3160 for fd in open_fds:
3161 p = subprocess.Popen([sys.executable, fd_status],
3162 stdout=subprocess.PIPE, close_fds=True,
3163 pass_fds=(fd, ))
3164 output, ignored = p.communicate()
3165
3166 remaining_fds = set(map(int, output.split(b',')))
3167 to_be_closed = open_fds - {fd}
3168
3169 self.assertIn(fd, remaining_fds, "fd to be passed not passed")
3170 self.assertFalse(remaining_fds & to_be_closed,
3171 "fd to be closed passed")
3172
3173 # pass_fds overrides close_fds with a warning.
3174 with self.assertWarns(RuntimeWarning) as context:
3175 self.assertFalse(subprocess.call(
3176 ZERO_RETURN_CMD,
3177 close_fds=False, pass_fds=(fd, )))
3178 self.assertIn('overriding close_fds', str(context.warning))
3179
3180 def test_pass_fds_inheritable(self):
3181 script = support.findfile("fd_status.py", subdir="subprocessdata")

Callers

nothing calls this directly

Calls 12

communicateMethod · 0.95
setFunction · 0.85
strFunction · 0.85
addCleanupMethod · 0.80
set_inheritableMethod · 0.80
assertInMethod · 0.80
assertFalseMethod · 0.80
assertWarnsMethod · 0.80
pipeMethod · 0.45
updateMethod · 0.45
splitMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected