summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-10-22 10:18:21 (GMT)
committerGitHub <noreply@github.com>2017-10-22 10:18:21 (GMT)
commitbcbdd2f8db396c3f0ec9186162b39b5a34effa0e (patch)
tree05d2eed9f796a47b994fac61902537947c2c6057 /Lib/test
parentdaeefd2e049b74340307481112a39f77de0f4769 (diff)
downloadcpython-bcbdd2f8db396c3f0ec9186162b39b5a34effa0e.zip
cpython-bcbdd2f8db396c3f0ec9186162b39b5a34effa0e.tar.gz
cpython-bcbdd2f8db396c3f0ec9186162b39b5a34effa0e.tar.bz2
bpo-28286: Add tests for the mode argument of GzipFile. (#4074)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_gzip.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index b457bd3..295d4d4 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -431,6 +431,30 @@ class TestGzip(BaseTest):
with gzip.GzipFile(fileobj=f, mode="w") as g:
pass
+ def test_fileobj_mode(self):
+ gzip.GzipFile(self.filename, "wb").close()
+ with open(self.filename, "r+b") as f:
+ with gzip.GzipFile(fileobj=f, mode='r') as g:
+ self.assertEqual(g.mode, gzip.READ)
+ with gzip.GzipFile(fileobj=f, mode='w') as g:
+ self.assertEqual(g.mode, gzip.WRITE)
+ with gzip.GzipFile(fileobj=f, mode='a') as g:
+ self.assertEqual(g.mode, gzip.WRITE)
+ with gzip.GzipFile(fileobj=f, mode='x') as g:
+ self.assertEqual(g.mode, gzip.WRITE)
+ with self.assertRaises(ValueError):
+ gzip.GzipFile(fileobj=f, mode='z')
+ for mode in "rb", "r+b":
+ with open(self.filename, mode) as f:
+ with gzip.GzipFile(fileobj=f) as g:
+ self.assertEqual(g.mode, gzip.READ)
+ for mode in "wb", "ab", "xb":
+ if "x" in mode:
+ support.unlink(self.filename)
+ with open(self.filename, mode) as f:
+ with gzip.GzipFile(fileobj=f) as g:
+ self.assertEqual(g.mode, gzip.WRITE)
+
def test_bytes_filename(self):
str_filename = self.filename
try: