summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorHynek Schlawack <hs@ox.cx>2012-06-21 18:20:25 (GMT)
committerHynek Schlawack <hs@ox.cx>2012-06-21 18:20:25 (GMT)
commit9ed8b4e4cac4f38109c3e08a8bfd19b7f6ad1c88 (patch)
treefbe94f34da9f31f1057dacf23a2e54caafd94240 /Lib/test
parent103e8113e4bb4ad3687d641f660481c72904d571 (diff)
downloadcpython-9ed8b4e4cac4f38109c3e08a8bfd19b7f6ad1c88.zip
cpython-9ed8b4e4cac4f38109c3e08a8bfd19b7f6ad1c88.tar.gz
cpython-9ed8b4e4cac4f38109c3e08a8bfd19b7f6ad1c88.tar.bz2
#10053: Don't close FDs when FileIO.__init__ fails
Loosely based on the work by Hirokazu Yamamoto.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_fileio.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
index 3588fb4..173ec25 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -403,6 +403,17 @@ class OtherFileTests(unittest.TestCase):
self.assertRaises(ValueError, _FileIO, "/some/invalid/name", "rt")
self.assertEqual(w.warnings, [])
+ def testUnclosedFDOnException(self):
+ class MyException(Exception): pass
+ class MyFileIO(_FileIO):
+ def __setattr__(self, name, value):
+ if name == "name":
+ raise MyException("blocked setting name")
+ return super(MyFileIO, self).__setattr__(name, value)
+ fd = os.open(__file__, os.O_RDONLY)
+ self.assertRaises(MyException, MyFileIO, fd)
+ os.close(fd) # should not raise OSError(EBADF)
+
def test_main():
# Historically, these tests have been sloppy about removing TESTFN.