[Python-checkins] r74175 - python/trunk/Lib/test/test_os.py

r.david.murray python-checkins at python.org
Wed Jul 22 19:22:59 CEST 2009


Author: r.david.murray
Date: Wed Jul 22 19:22:58 2009
New Revision: 74175

Log:
Backport of fix for issue 6542: make sure
test_os.TestInvalidFD.test_closerange does not close any
valid file descriptors.


Modified:
   python/trunk/Lib/test/test_os.py

Modified: python/trunk/Lib/test/test_os.py
==============================================================================
--- python/trunk/Lib/test/test_os.py	(original)
+++ python/trunk/Lib/test/test_os.py	Wed Jul 22 19:22:58 2009
@@ -563,7 +563,18 @@
     def test_closerange(self):
         if hasattr(os, "closerange"):
             fd = test_support.make_bad_fd()
-            self.assertEqual(os.closerange(fd, fd + 10), None)
+            # Make sure none of the descriptors we are about to close are
+            # currently valid (issue 6542).
+            for i in range(10):
+                try: os.fstat(fd+i)
+                except OSError:
+                    pass
+                else:
+                    break
+            if i < 2:
+                raise unittest.SkipTest(
+                    "Unable to acquire a range of invalid file descriptors")
+            self.assertEqual(os.closerange(fd, fd + i-1), None)
 
     def test_dup2(self):
         if hasattr(os, "dup2"):


More information about the Python-checkins mailing list