summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2008-08-17 14:43:41 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2008-08-17 14:43:41 (GMT)
commitbebb18bef5864e9b73400e5bda87cdf3f38248e1 (patch)
tree40a1a03a1ad352e65ebb7c3fcdab3df9fb08f923
parent41a81eb6cb05bb9b8799a145509a27e81d357601 (diff)
downloadcpython-bebb18bef5864e9b73400e5bda87cdf3f38248e1.zip
cpython-bebb18bef5864e9b73400e5bda87cdf3f38248e1.tar.gz
cpython-bebb18bef5864e9b73400e5bda87cdf3f38248e1.tar.bz2
backport r65723: strengthen test_os.test_closerange
-rw-r--r--Lib/test/test_os.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 4c00422..7cfae44 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -24,10 +24,28 @@ class FileTests(unittest.TestCase):
self.assert_(os.access(test_support.TESTFN, os.W_OK))
def test_closerange(self):
- f = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR)
+ first = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR)
+ # We must allocate two consecutive file descriptors, otherwise
+ # it will mess up other file descriptors (perhaps even the three
+ # standard ones).
+ second = os.dup(first)
+ try:
+ retries = 0
+ while second != first + 1:
+ os.close(first)
+ retries += 1
+ if retries > 10:
+ # XXX test skipped
+ print >> sys.stderr, (
+ "couldn't allocate two consecutive fds, "
+ "skipping test_closerange")
+ return
+ first, second = second, os.dup(second)
+ finally:
+ os.close(second)
# close a fd that is open, and one that isn't
- os.closerange(f, f+2)
- self.assertRaises(OSError, os.write, f, "a")
+ os.closerange(first, first + 2)
+ self.assertRaises(OSError, os.write, first, "a")
class TemporaryFileTests(unittest.TestCase):