mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
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.
This commit is contained in:
parent
e7bd868429
commit
8043cf868c
3 changed files with 81 additions and 36 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue