diff options
Diffstat (limited to 'Lib/test/test_gzip.py')
-rw-r--r-- | Lib/test/test_gzip.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py index a95af05..e49fe00 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -22,6 +22,17 @@ data2 = b"""/* zlibmodule.c -- gzip-compatible data compression */ """ +class UnseekableIO(io.BytesIO): + def seekable(self): + return False + + def tell(self): + raise io.UnsupportedOperation + + def seek(self, *args): + raise io.UnsupportedOperation + + class TestGzip(unittest.TestCase): filename = support.TESTFN @@ -265,6 +276,16 @@ class TestGzip(unittest.TestCase): d = f.read() self.assertEqual(d, data1 * 50, "Incorrect data in file") + def test_non_seekable_file(self): + uncompressed = data1 * 50 + buf = UnseekableIO() + with gzip.GzipFile(fileobj=buf, mode="wb") as f: + f.write(uncompressed) + compressed = buf.getvalue() + buf = UnseekableIO(compressed) + with gzip.GzipFile(fileobj=buf, mode="rb") as f: + self.assertEqual(f.read(), uncompressed) + # Testing compress/decompress shortcut functions def test_compress(self): |