diff options
author | Christian Heimes <christian@cheimes.de> | 2008-11-05 19:30:32 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-11-05 19:30:32 (GMT) |
commit | ecc42a2b82858763818484572dccc7e88a3bdda1 (patch) | |
tree | a8bad97b03850ab5ccbe33e14332e4840b409816 /Lib/test/test_io.py | |
parent | b37509b11b34fb4b2045162b88d4fa110cd4692b (diff) | |
download | cpython-ecc42a2b82858763818484572dccc7e88a3bdda1.zip cpython-ecc42a2b82858763818484572dccc7e88a3bdda1.tar.gz cpython-ecc42a2b82858763818484572dccc7e88a3bdda1.tar.bz2 |
Fixed issue #4233.
Changed semantic of _fileio.FileIO's close() method on file objects with closefd=False. The file descriptor is still kept open but the file object behaves like a closed file. The FileIO object also got a new readonly attribute closefd.
Approved by Barry
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r-- | Lib/test/test_io.py | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index f28bade..1f0295c 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -272,6 +272,29 @@ class IOTest(unittest.TestCase): self.assertRaises(ValueError, io.open, support.TESTFN, 'w', closefd=False) + def testReadClosed(self): + with io.open(support.TESTFN, "w") as f: + f.write("egg\n") + with io.open(support.TESTFN, "r") as f: + file = io.open(f.fileno(), "r", closefd=False) + self.assertEqual(file.read(), "egg\n") + file.seek(0) + file.close() + self.assertRaises(ValueError, file.read) + + def test_no_closefd_with_filename(self): + # can't use closefd in combination with a file name + self.assertRaises(ValueError, io.open, support.TESTFN, "r", closefd=False) + + def test_closefd_attr(self): + with io.open(support.TESTFN, "wb") as f: + f.write(b"egg\n") + with io.open(support.TESTFN, "r") as f: + self.assertEqual(f.buffer.raw.closefd, True) + file = io.open(f.fileno(), "r", closefd=False) + self.assertEqual(file.buffer.raw.closefd, False) + + class MemorySeekTestMixin: def testInit(self): @@ -1237,15 +1260,6 @@ class MiscIOTest(unittest.TestCase): else: self.assert_(issubclass(obj, io.IOBase)) - def test_fileio_warnings(self): - with support.check_warnings() as w: - self.assertEqual(w.warnings, []) - self.assertRaises(TypeError, io.FileIO, []) - self.assertEqual(w.warnings, []) - self.assertRaises(ValueError, io.FileIO, "/some/invalid/name", "rt") - self.assertEqual(w.warnings, []) - - def test_main(): support.run_unittest(IOTest, BytesIOTest, StringIOTest, BufferedReaderTest, BufferedWriterTest, |