Issue #15247: FileIO now raises an error when given a file descriptor pointing to a directory.

This commit is contained in:
Antoine Pitrou 2012-07-06 18:48:24 +02:00
parent 01cca5e451
commit 9235b254dc
3 changed files with 16 additions and 12 deletions

View file

@ -127,6 +127,14 @@ class AutoFileTests(unittest.TestCase):
else:
self.fail("Should have raised IOError")
@unittest.skipIf(os.name == 'nt', "test only works on a POSIX-like system")
def testOpenDirFD(self):
fd = os.open('.', os.O_RDONLY)
with self.assertRaises(IOError) as cm:
_FileIO(fd, 'r')
os.close(fd)
self.assertEqual(cm.exception.errno, errno.EISDIR)
#A set of functions testing that we get expected behaviour if someone has
#manually closed the internal file descriptor. First, a decorator:
def ClosedFD(func):