summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorHynek Schlawack <hs@ox.cx>2012-06-21 17:45:19 (GMT)
committerHynek Schlawack <hs@ox.cx>2012-06-21 17:45:19 (GMT)
commit9bd4bf2a3d0426ee3830e89854ecf4bea03ac830 (patch)
treef75e9f2cb4374fd0e4ce88578e0b2552876ace70 /Lib
parent4215d2738a44be9eca09eb7b48c31ed805c8fb60 (diff)
downloadcpython-9bd4bf2a3d0426ee3830e89854ecf4bea03ac830.zip
cpython-9bd4bf2a3d0426ee3830e89854ecf4bea03ac830.tar.gz
cpython-9bd4bf2a3d0426ee3830e89854ecf4bea03ac830.tar.bz2
#10053: Don't close FDs when FileIO.__init__ fails
Loosely based on the work by Hirokazu Yamamoto.
Diffstat (limited to 'Lib')
-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 9688ffc..4d13ce5 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -421,6 +421,17 @@ class OtherFileTests(unittest.TestCase):
'IOError: [Errno 2] No such file or directory' not in out):
self.fail('Bad output: %r' % out)
+ 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.
# So get rid of it no matter what.