]> granicus.if.org Git - python/commitdiff
Backport of fix for issue 6542: make sure
authorR. David Murray <rdmurray@bitdance.com>
Wed, 22 Jul 2009 17:22:58 +0000 (17:22 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Wed, 22 Jul 2009 17:22:58 +0000 (17:22 +0000)
test_os.TestInvalidFD.test_closerange does not close any
valid file descriptors.

Lib/test/test_os.py

index fa82a754b009ba9d96162a58df84a43e94e0b4d2..207963e6fc297e50640250003bc99795735d8bc9 100644 (file)
@@ -563,7 +563,18 @@ class TestInvalidFD(unittest.TestCase):
     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"):