diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-23 16:22:51 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-23 16:22:51 (GMT) |
commit | 7b9698435d890b2df5107a6a3efedc1aebc178a3 (patch) | |
tree | 8552eb6b9fa4cf0861e8252cb3fe92be82011d1d /Lib/test | |
parent | dda7fdf1947453dc4c7b167c75b111b81e4b881e (diff) | |
download | cpython-7b9698435d890b2df5107a6a3efedc1aebc178a3.zip cpython-7b9698435d890b2df5107a6a3efedc1aebc178a3.tar.gz cpython-7b9698435d890b2df5107a6a3efedc1aebc178a3.tar.bz2 |
Issue #1675951: Allow GzipFile to work with unseekable file objects.
Patch by Florian Festi.
Diffstat (limited to 'Lib/test')
-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): |