summaryrefslogtreecommitdiff
path: root/Lib/test/test_gzip.py
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2012-06-04 23:21:38 +0200
committerNadeem Vawda <nadeem.vawda@gmail.com>2012-06-04 23:21:38 +0200
commit68721019efb16ba8acad036c331a9a195d6f7da0 (patch)
tree3fad6d5d15ea939af5327415a1cae0de9a80956d /Lib/test/test_gzip.py
parentd7b7c7472b274c6867261b3a796c2aada9945849 (diff)
downloadcpython-git-68721019efb16ba8acad036c331a9a195d6f7da0.tar.gz
Add fileobj support to gzip.open().
Diffstat (limited to 'Lib/test/test_gzip.py')
-rw-r--r--Lib/test/test_gzip.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index 270411bd80..bb9709776f 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -424,8 +424,21 @@ class TestOpen(BaseTest):
file_data = gzip.decompress(f.read()).decode("ascii")
self.assertEqual(file_data, uncompressed_raw * 2)
+ def test_fileobj(self):
+ uncompressed_bytes = data1 * 50
+ uncompressed_str = uncompressed_bytes.decode("ascii")
+ compressed = gzip.compress(uncompressed_bytes)
+ with gzip.open(io.BytesIO(compressed), "r") as f:
+ self.assertEqual(f.read(), uncompressed_bytes)
+ with gzip.open(io.BytesIO(compressed), "rb") as f:
+ self.assertEqual(f.read(), uncompressed_bytes)
+ with gzip.open(io.BytesIO(compressed), "rt") as f:
+ self.assertEqual(f.read(), uncompressed_str)
+
def test_bad_params(self):
# Test invalid parameter combinations.
+ with self.assertRaises(TypeError):
+ gzip.open(123.456)
with self.assertRaises(ValueError):
gzip.open(self.filename, "wbt")
with self.assertRaises(ValueError):