mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
#10053: Don't close FDs when FileIO.__init__ fails
Loosely based on the work by Hirokazu Yamamoto.
This commit is contained in:
parent
4215d2738a
commit
9bd4bf2a3d
3 changed files with 20 additions and 6 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue