summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_gzip.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-10-06 21:21:18 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-10-06 21:21:18 (GMT)
commit7980eaa98d7a4448d3e0a6f336a0dd55f0346b8f (patch)
treedc4f1cdfc6511cbc073f63d17bdca0bf8e5272c1 /Lib/test/test_gzip.py
parentcd889af91730b35fc39ec5cd318d16e9cf8391f1 (diff)
downloadcpython-7980eaa98d7a4448d3e0a6f336a0dd55f0346b8f.zip
cpython-7980eaa98d7a4448d3e0a6f336a0dd55f0346b8f.tar.gz
cpython-7980eaa98d7a4448d3e0a6f336a0dd55f0346b8f.tar.bz2
Issue #9759: GzipFile now raises ValueError when an operation is attempted
after the file is closed. Patch by Jeffrey Finkelstein.
Diffstat (limited to 'Lib/test/test_gzip.py')
-rw-r--r--Lib/test/test_gzip.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index 8e493b5..4a364c2 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -62,6 +62,28 @@ class TestGzip(unittest.TestCase):
f = gzip.GzipFile(self.filename, 'r') ; d = f.read() ; f.close()
self.assertEqual(d, data1*50)
+ def test_io_on_closed_object(self):
+ # Test that I/O operations on closed GzipFile objects raise a
+ # ValueError, just like the corresponding functions on file objects.
+
+ # Write to a file, open it for reading, then close it.
+ self.test_write()
+ f = gzip.GzipFile(self.filename, 'r')
+ f.close()
+ with self.assertRaises(ValueError):
+ f.read(1)
+ with self.assertRaises(ValueError):
+ f.seek(0)
+ with self.assertRaises(ValueError):
+ f.tell()
+ # Open the file for writing, then close it.
+ f = gzip.GzipFile(self.filename, 'w')
+ f.close()
+ with self.assertRaises(ValueError):
+ f.write(b'')
+ with self.assertRaises(ValueError):
+ f.flush()
+
def test_append(self):
self.test_write()
# Append to the previous file