Skip to content

Commit f6fa22e

Browse files
committed
Issue python#18571: Merge duplicate test code
Merge test/subprocessdata/inherited.py into test/subprocessdata/fd_status.py
1 parent 8913a6c commit f6fa22e

File tree

3 files changed

+18
-31
lines changed

3 files changed

+18
-31
lines changed

Lib/test/subprocessdata/fd_status.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
"""When called as a script, print a comma-separated list of the open
2-
file descriptors on stdout."""
2+
file descriptors on stdout.
3+
4+
Usage:
5+
fd_stats.py: check all file descriptors
6+
fd_status.py fd1 fd2 ...: check only specified file descriptors
7+
"""
38

49
import errno
510
import os
611
import stat
7-
8-
try:
9-
_MAXFD = os.sysconf("SC_OPEN_MAX")
10-
except:
11-
_MAXFD = 256
12+
import sys
1213

1314
if __name__ == "__main__":
1415
fds = []
15-
for fd in range(0, _MAXFD):
16+
if len(sys.argv) == 1:
17+
try:
18+
_MAXFD = os.sysconf("SC_OPEN_MAX")
19+
except:
20+
_MAXFD = 256
21+
test_fds = range(0, _MAXFD)
22+
else:
23+
test_fds = map(int, sys.argv[1:])
24+
for fd in test_fds:
1625
try:
1726
st = os.fstat(fd)
1827
except OSError as e:

Lib/test/subprocessdata/inherited.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

Lib/test/test_subprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,7 @@ def test_pass_fds(self):
19261926
self.assertIn('overriding close_fds', str(context.warning))
19271927

19281928
def test_pass_fds_inheritable(self):
1929-
script = support.findfile("inherited.py", subdir="subprocessdata")
1929+
script = support.findfile("fd_status.py", subdir="subprocessdata")
19301930

19311931
inheritable, non_inheritable = os.pipe()
19321932
self.addCleanup(os.close, inheritable)
@@ -1945,7 +1945,7 @@ def test_pass_fds_inheritable(self):
19451945

19461946
# the inheritable file descriptor must be inherited, so its inheritable
19471947
# flag must be set in the child process after fork() and before exec()
1948-
self.assertEqual(fds, set(pass_fds))
1948+
self.assertEqual(fds, set(pass_fds), "output=%a" % output)
19491949

19501950
# inheritable flag must not be changed in the parent process
19511951
self.assertEqual(os.get_inheritable(inheritable), True)

0 commit comments

Comments
 (0)