summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-01-26 12:01:27 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-01-26 12:01:27 (GMT)
commita14f7d239f000d889e38d818fb65df79700192ad (patch)
tree7763aef6ceade68e553aa23b75e3b1d475f57319 /Lib/test/test_zipfile.py
parentf15e52402640284b01860b6f56dfa50d7efda67b (diff)
downloadcpython-a14f7d239f000d889e38d818fb65df79700192ad.zip
cpython-a14f7d239f000d889e38d818fb65df79700192ad.tar.gz
cpython-a14f7d239f000d889e38d818fb65df79700192ad.tar.bz2
Issue #14099: Restored support of writing ZIP files to tellable but
non-seekable streams.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 57431c7..abe80e4 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -1668,6 +1668,34 @@ class LzmaTestsWithRandomBinaryFiles(AbstractTestsWithRandomBinaryFiles,
compression = zipfile.ZIP_LZMA
+# Privide the tell() method but not seek()
+class Tellable:
+ def __init__(self, fp):
+ self.fp = fp
+ self.offset = 0
+
+ def write(self, data):
+ self.offset += self.fp.write(data)
+
+ def tell(self):
+ return self.offset
+
+ def flush(self):
+ pass
+
+class UnseekableTests(unittest.TestCase):
+ def test_writestr_tellable(self):
+ f = io.BytesIO()
+ with zipfile.ZipFile(Tellable(f), 'w', zipfile.ZIP_STORED) as zipfp:
+ zipfp.writestr('ones', b'111')
+ zipfp.writestr('twos', b'222')
+ with zipfile.ZipFile(f, mode='r') as zipf:
+ with zipf.open('ones') as zopen:
+ self.assertEqual(zopen.read(), b'111')
+ with zipf.open('twos') as zopen:
+ self.assertEqual(zopen.read(), b'222')
+
+
@requires_zlib
class TestsWithMultipleOpens(unittest.TestCase):
@classmethod