summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRichard Oudkerk <shibturn@gmail.com>2012-07-06 11:05:32 (GMT)
committerRichard Oudkerk <shibturn@gmail.com>2012-07-06 11:05:32 (GMT)
commit2240ac1eae2dd8674748239af9c61e5ab4faeb2c (patch)
tree9e851d9c9d9df1a377e1fd95ed27a9f29f923313 /Lib/test
parent74de1536810946f82c1e6526fff55646fa119b3d (diff)
downloadcpython-2240ac1eae2dd8674748239af9c61e5ab4faeb2c.zip
cpython-2240ac1eae2dd8674748239af9c61e5ab4faeb2c.tar.gz
cpython-2240ac1eae2dd8674748239af9c61e5ab4faeb2c.tar.bz2
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_genericpath.py10
-rw-r--r--Lib/test/test_os.py13
2 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py
index ebb8396..fc3d44c 100644
--- a/Lib/test/test_genericpath.py
+++ b/Lib/test/test_genericpath.py
@@ -146,6 +146,16 @@ class GenericTest(unittest.TestCase):
f.close()
support.unlink(support.TESTFN)
+ @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()")
+ def test_exists_fd(self):
+ r, w = os.pipe()
+ try:
+ self.assertTrue(self.pathmodule.exists(r))
+ finally:
+ os.close(r)
+ os.close(w)
+ self.assertFalse(self.pathmodule.exists(r))
+
def test_isdir(self):
self.assertIs(self.pathmodule.isdir(support.TESTFN), False)
f = open(support.TESTFN, "wb")
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 57de993..7c73f1e 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -473,6 +473,19 @@ class StatAttributeTests(unittest.TestCase):
return
self.fail("Could not stat pagefile.sys")
+ @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()")
+ def test_15261(self):
+ # Verify that stat'ing a closed fd does not cause crash
+ r, w = os.pipe()
+ try:
+ os.stat(r) # should not raise error
+ finally:
+ os.close(r)
+ os.close(w)
+ with self.assertRaises(OSError) as ctx:
+ os.stat(r)
+ self.assertEqual(ctx.exception.errno, errno.EBADF)
+
from test import mapping_tests
class EnvironTests(mapping_tests.BasicTestMappingProtocol):