Skip to content

Commit 57b9ed1

Browse files
author
apetrov
committed
Add tests iterable: sum streams exceed zip64limit with not allowed zip64
add tests iterable: sum streams exceed zip64limit with allowed zip64
1 parent 41bb027 commit 57b9ed1

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

tests/test_zipstream.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,108 @@ def test_write_iterable_no_archive(self):
9696
z = zipstream.ZipFile(mode='w')
9797
self.assertRaises(TypeError, z.write_iter, iterable=range(10))
9898

99+
def test_write_iterable_zip64_with_not_allow_zip64_many_smalls(self):
100+
# check many small streams that sum length require ZIP64 extensions when not allowed zip64
101+
z = zipstream.ZipFile(mode='w', allowZip64=False)
102+
103+
def string_small_generator():
104+
counter = 0
105+
sample = b'zipstream0' * 10000000
106+
len_sample = len(sample)
107+
while counter + len_sample < zipstream.ZIP64_LIMIT:
108+
counter += len_sample
109+
yield sample
110+
111+
data = [string_small_generator(), string_small_generator()]
112+
for i, d in enumerate(data):
113+
z.write_iter(iterable=d, arcname='data_{0}'.format(i))
114+
f = tempfile.NamedTemporaryFile(suffix='zip', delete=False)
115+
try:
116+
with self.assertRaises(zipfile.LargeZipFile):
117+
for chunk in z:
118+
f.write(chunk)
119+
f.close()
120+
except Exception:
121+
raise
122+
finally:
123+
os.remove(f.name)
124+
125+
def test_write_iterable_zip64_with_not_allow_zip64_1_big_file(self):
126+
# check 1 big stream that length require ZIP64 extensions when not allowed zip64
127+
z = zipstream.ZipFile(mode='w', allowZip64=False)
128+
129+
def string_big_generator():
130+
counter = 0
131+
sample = b'zipstream0' * 10000000
132+
len_sample = len(sample)
133+
while counter < zipstream.ZIP64_LIMIT:
134+
counter += len_sample
135+
yield sample
136+
137+
data = [string_big_generator()]
138+
for i, d in enumerate(data):
139+
z.write_iter(iterable=d, arcname='data_{0}'.format(i))
140+
f = tempfile.NamedTemporaryFile(suffix='zip', delete=False)
141+
try:
142+
with self.assertRaises(zipfile.LargeZipFile):
143+
for chunk in z:
144+
f.write(chunk)
145+
f.close()
146+
except Exception:
147+
raise
148+
finally:
149+
os.remove(f.name)
150+
151+
def test_write_iterable_zip64_with_allow_zip64_many_smalls(self):
152+
# check many small streams that sum length require ZIP64 extensions when allowed zip64
153+
z = zipstream.ZipFile(mode='w', allowZip64=True)
154+
155+
def string_small_generator():
156+
counter = 0
157+
sample = b'zipstream0' * 10000000
158+
len_sample = len(sample)
159+
while counter + len_sample < zipstream.ZIP64_LIMIT:
160+
counter += len_sample
161+
yield sample
162+
163+
data = [string_small_generator(), string_small_generator()]
164+
for i, d in enumerate(data):
165+
z.write_iter(iterable=d, arcname='data_{0}'.format(i))
166+
f = tempfile.NamedTemporaryFile(suffix='zip', delete=False)
167+
try:
168+
for chunk in z:
169+
f.write(chunk)
170+
f.close()
171+
except Exception:
172+
raise
173+
finally:
174+
os.remove(f.name)
175+
176+
def test_write_iterable_zip64_with_allow_zip64_1_big_file(self):
177+
# check 1 big stream that length require ZIP64 extensions when allowed zip64
178+
z = zipstream.ZipFile(mode='w', allowZip64=True)
179+
180+
def string_big_generator():
181+
counter = 0
182+
sample = b'zipstream0' * 10000000
183+
len_sample = len(sample)
184+
while counter < zipstream.ZIP64_LIMIT:
185+
counter += len_sample
186+
yield sample
187+
188+
data = [string_big_generator()]
189+
for i, d in enumerate(data):
190+
z.write_iter(iterable=d, arcname='data_{0}'.format(i))
191+
f = tempfile.NamedTemporaryFile(suffix='zip', delete=False)
192+
try:
193+
for chunk in z:
194+
f.write(chunk)
195+
f.close()
196+
except Exception:
197+
raise
198+
finally:
199+
os.remove(f.name)
200+
201+
99202
if __name__ == '__main__':
100203
unittest.main()

0 commit comments

Comments
 (0)