summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_fileio.py
diff options
context:
space:
mode:
authorHynek Schlawack <hs@ox.cx>2012-06-21 18:58:31 (GMT)
committerHynek Schlawack <hs@ox.cx>2012-06-21 18:58:31 (GMT)
commit69168354c254f72b7a13d35aff8bb02752d00d26 (patch)
treed0ca31048f26181e9cba9a8ea1c1fd69fa2ae70c /Lib/test/test_fileio.py
parenta759d4e9f40fd0b757600d5fd3666cdddee113fe (diff)
parent9ed8b4e4cac4f38109c3e08a8bfd19b7f6ad1c88 (diff)
downloadcpython-69168354c254f72b7a13d35aff8bb02752d00d26.zip
cpython-69168354c254f72b7a13d35aff8bb02752d00d26.tar.gz
cpython-69168354c254f72b7a13d35aff8bb02752d00d26.tar.bz2
#10053: Don't close FDs when FileIO.__init__ fails
Loosely based on the work by Hirokazu Yamamoto.
Diffstat (limited to 'Lib/test/test_fileio.py')
-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 9854d0c..99f2069 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -404,6 +404,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.