]> granicus.if.org Git - python/commitdiff
Issue 6542: Make sure that TestInvalidFD.test_closerange does not
authorR. David Murray <rdmurray@bitdance.com>
Wed, 22 Jul 2009 15:20:27 +0000 (15:20 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Wed, 22 Jul 2009 15:20:27 +0000 (15:20 +0000)
close any valid file descriptors.

Lib/test/test_os.py

index 63f409e95838cf9f1f5bc7387fe6e3fce977b8a6..62edd6c4fb9268956cb9ff7e28dfd2d1c819d466 100644 (file)
@@ -617,7 +617,18 @@ class TestInvalidFD(unittest.TestCase):
     def test_closerange(self):
         if hasattr(os, "closerange"):
             fd = 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"):