mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
#4841: Fix FileIO constructor to honor closefd when called repeatedly
Patch by Victor Stinner.
This commit is contained in:
commit
9866d96e48
2 changed files with 20 additions and 3 deletions
|
|
@ -643,6 +643,19 @@ class IOTest(unittest.TestCase):
|
|||
with self.open("non-existent", "r", opener=opener) as f:
|
||||
self.assertEqual(f.read(), "egg\n")
|
||||
|
||||
def test_fileio_closefd(self):
|
||||
# Issue #4841
|
||||
with self.open(__file__, 'rb') as f1, \
|
||||
self.open(__file__, 'rb') as f2:
|
||||
fileio = self.FileIO(f1.fileno(), closefd=False)
|
||||
# .__init__() must not close f1
|
||||
fileio.__init__(f2.fileno(), closefd=False)
|
||||
f1.readline()
|
||||
# .close() must not close f2
|
||||
fileio.close()
|
||||
f2.readline()
|
||||
|
||||
|
||||
class CIOTest(IOTest):
|
||||
|
||||
def test_IOBase_finalize(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue