[Python-checkins] bpo-28286: Add tests for the mode argument of GzipFile. (GH-4074) (#4076)

Serhiy Storchaka webhook-mailer at python.org
Sun Oct 22 07:53:47 EDT 2017


https://github.com/python/cpython/commit/251de30935490a702b0a365f1e9bea696b39c016
commit: 251de30935490a702b0a365f1e9bea696b39c016
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2017年10月22日T14:53:43+03:00
summary:
bpo-28286: Add tests for the mode argument of GzipFile. (GH-4074) (#4076)
(cherry picked from commit bcbdd2f8db396c3f0ec9186162b39b5a34effa0e)
files:
M Lib/test/test_gzip.py
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index b457bd3f44d..295d4d4a8fd 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -431,6 +431,30 @@ def test_fileobj_from_fdopen(self):
 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:


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /