summaryrefslogtreecommitdiffstats
path: root/Lib/test/subprocessdata
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-09-01 08:22:41 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-09-01 08:22:41 (GMT)
commitf6fa22efe0fbc726583ec268a80fdb671b148b2c (patch)
treed61564ca3bc313f08c062ea0fa215c739df330c6 /Lib/test/subprocessdata
parent8913a6c83dd34300f4a13950036b01c0e2cad1b0 (diff)
downloadcpython-f6fa22efe0fbc726583ec268a80fdb671b148b2c.zip
cpython-f6fa22efe0fbc726583ec268a80fdb671b148b2c.tar.gz
cpython-f6fa22efe0fbc726583ec268a80fdb671b148b2c.tar.bz2
Issue #18571: Merge duplicate test code
Merge test/subprocessdata/inherited.py into test/subprocessdata/fd_status.py
Diffstat (limited to 'Lib/test/subprocessdata')
-rw-r--r--Lib/test/subprocessdata/fd_status.py23
-rw-r--r--Lib/test/subprocessdata/inherited.py22
2 files changed, 16 insertions, 29 deletions
diff --git a/Lib/test/subprocessdata/fd_status.py b/Lib/test/subprocessdata/fd_status.py
index 877512a..d12bd95 100644
--- a/Lib/test/subprocessdata/fd_status.py
+++ b/Lib/test/subprocessdata/fd_status.py
@@ -1,18 +1,27 @@
"""When called as a script, print a comma-separated list of the open
-file descriptors on stdout."""
+file descriptors on stdout.
+
+Usage:
+fd_stats.py: check all file descriptors
+fd_status.py fd1 fd2 ...: check only specified file descriptors
+"""
import errno
import os
import stat
-
-try:
- _MAXFD = os.sysconf("SC_OPEN_MAX")
-except:
- _MAXFD = 256
+import sys
if __name__ == "__main__":
fds = []
- for fd in range(0, _MAXFD):
+ if len(sys.argv) == 1:
+ try:
+ _MAXFD = os.sysconf("SC_OPEN_MAX")
+ except:
+ _MAXFD = 256
+ test_fds = range(0, _MAXFD)
+ else:
+ test_fds = map(int, sys.argv[1:])
+ for fd in test_fds:
try:
st = os.fstat(fd)
except OSError as e:
diff --git a/Lib/test/subprocessdata/inherited.py b/Lib/test/subprocessdata/inherited.py
deleted file mode 100644
index 1aac041..0000000
--- a/Lib/test/subprocessdata/inherited.py
+++ /dev/null
@@ -1,22 +0,0 @@
-"""Similar to fd_status.py, but only checks file descriptors passed on the
-command line."""
-
-import errno
-import os
-import sys
-import stat
-
-if __name__ == "__main__":
- fds = map(int, sys.argv[1:])
- inherited = []
- for fd in fds:
- try:
- st = os.fstat(fd)
- except OSError as e:
- if e.errno == errno.EBADF:
- continue
- raise
- # Ignore Solaris door files
- if not stat.S_ISDOOR(st.st_mode):
- inherited.append(fd)
- print(','.join(map(str, inherited)))