[Python-checkins] cpython: Issue #18571: Merge duplicate test code

victor.stinner python-checkins at python.org
Sun Sep 1 10:22:52 CEST 2013


http://hg.python.org/cpython/rev/c27527dce71e
changeset:   85491:c27527dce71e
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Sun Sep 01 10:22:41 2013 +0200
summary:
  Issue #18571: Merge duplicate test code

Merge test/subprocessdata/inherited.py into test/subprocessdata/fd_status.py

files:
  Lib/test/subprocessdata/fd_status.py |  23 +++++++++++----
  Lib/test/subprocessdata/inherited.py |  22 ---------------
  Lib/test/test_subprocess.py          |   4 +-
  3 files changed, 18 insertions(+), 31 deletions(-)


diff --git a/Lib/test/subprocessdata/fd_status.py b/Lib/test/subprocessdata/fd_status.py
--- 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
--- 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)))
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1926,7 +1926,7 @@
             self.assertIn('overriding close_fds', str(context.warning))
 
     def test_pass_fds_inheritable(self):
-        script = support.findfile("inherited.py", subdir="subprocessdata")
+        script = support.findfile("fd_status.py", subdir="subprocessdata")
 
         inheritable, non_inheritable = os.pipe()
         self.addCleanup(os.close, inheritable)
@@ -1945,7 +1945,7 @@
 
         # the inheritable file descriptor must be inherited, so its inheritable
         # flag must be set in the child process after fork() and before exec()
-        self.assertEqual(fds, set(pass_fds))
+        self.assertEqual(fds, set(pass_fds), "output=%a" % output)
 
         # inheritable flag must not be changed in the parent process
         self.assertEqual(os.get_inheritable(inheritable), True)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list