diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-01-09 19:54:29 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-01-09 19:54:29 (GMT) |
commit | 8043cf868c5fc045f513c02b51c89f313c738246 (patch) | |
tree | 3f80e7cab718afc88120f224aa7e3a3dee313683 /Lib/test/test_io.py | |
parent | e7bd868429af3e3a1091e2cf83731530561579a1 (diff) | |
download | cpython-8043cf868c5fc045f513c02b51c89f313c738246.zip cpython-8043cf868c5fc045f513c02b51c89f313c738246.tar.gz cpython-8043cf868c5fc045f513c02b51c89f313c738246.tar.bz2 |
Issue #4604: Some objects of the I/O library could still be used after
having been closed (for instance, a read() call could return some
previously buffered data). Patch by Dmitry Vasiliev.
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r-- | Lib/test/test_io.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index af5b6f4..e8bba86 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -1324,6 +1324,45 @@ class MiscIOTest(unittest.TestCase): f.close() g.close() + def test_io_after_close(self): + for kwargs in [ + {"mode": "w"}, + {"mode": "wb"}, + {"mode": "w", "buffering": 1}, + {"mode": "w", "buffering": 2}, + {"mode": "wb", "buffering": 0}, + {"mode": "r"}, + {"mode": "rb"}, + {"mode": "r", "buffering": 1}, + {"mode": "r", "buffering": 2}, + {"mode": "rb", "buffering": 0}, + {"mode": "w+"}, + {"mode": "w+b"}, + {"mode": "w+", "buffering": 1}, + {"mode": "w+", "buffering": 2}, + {"mode": "w+b", "buffering": 0}, + ]: + f = io.open(support.TESTFN, **kwargs) + f.close() + self.assertRaises(ValueError, f.flush) + self.assertRaises(ValueError, f.fileno) + self.assertRaises(ValueError, f.isatty) + self.assertRaises(ValueError, f.__iter__) + if hasattr(f, "peek"): + self.assertRaises(ValueError, f.peek, 1) + self.assertRaises(ValueError, f.read) + if hasattr(f, "read1"): + self.assertRaises(ValueError, f.read1, 1024) + if hasattr(f, "readinto"): + self.assertRaises(ValueError, f.readinto, bytearray(1024)) + self.assertRaises(ValueError, f.readline) + self.assertRaises(ValueError, f.readlines) + self.assertRaises(ValueError, f.seek, 0) + self.assertRaises(ValueError, f.tell) + self.assertRaises(ValueError, f.truncate) + self.assertRaises(ValueError, f.write, "") + self.assertRaises(ValueError, f.writelines, []) + def test_main(): support.run_unittest(IOTest, BytesIOTest, StringIOTest, |