From 877effc2986ad30ecd5454811b0449bcfe3037f5 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Fri, 25 May 2012 09:24:18 +0200 Subject: #4841: Fix FileIO constructor to honor closefd when called repeatedly Patch by Victor Stinner. --- Lib/test/test_io.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Lib/test/test_io.py') diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index b9972f3ac5..72feff59e4 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -593,6 +593,19 @@ class IOTest(unittest.TestCase): self.assertEqual(rawio.read(2), None) self.assertEqual(rawio.read(2), b"") + 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): -- cgit v1.2.1