summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_gzip.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-09-29 10:49:46 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-09-29 10:49:46 (GMT)
commitc3ed2e7f8326d703ed971220a7eb76317341efbf (patch)
treed7bfa945b55a990f608aa5ccb9b8a3caaac2a02d /Lib/test/test_gzip.py
parent4c2e4fa242d2567e6f0bb5d112cc4e3c5d085b68 (diff)
downloadcpython-c3ed2e7f8326d703ed971220a7eb76317341efbf.zip
cpython-c3ed2e7f8326d703ed971220a7eb76317341efbf.tar.gz
cpython-c3ed2e7f8326d703ed971220a7eb76317341efbf.tar.bz2
Issue #9962: GzipFile now has the peek() method.
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 e49fe00..8e493b5 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -286,6 +286,28 @@ class TestGzip(unittest.TestCase):
with gzip.GzipFile(fileobj=buf, mode="rb") as f:
self.assertEqual(f.read(), uncompressed)
+ def test_peek(self):
+ uncompressed = data1 * 200
+ with gzip.GzipFile(self.filename, "wb") as f:
+ f.write(uncompressed)
+
+ def sizes():
+ while True:
+ for n in range(5, 50, 10):
+ yield n
+
+ with gzip.GzipFile(self.filename, "rb") as f:
+ f.max_read_chunk = 33
+ nread = 0
+ for n in sizes():
+ s = f.peek(n)
+ if s == b'':
+ break
+ self.assertEqual(f.read(len(s)), s)
+ nread += len(s)
+ self.assertEqual(f.read(100), b'')
+ self.assertEqual(nread, len(uncompressed))
+
# Testing compress/decompress shortcut functions
def test_compress(self):