Skip to content

Commit 7a1ca87

Browse files
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 7a1ca87

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

tests/test_zipstream.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,104 @@ 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+
self.assertRaises(zipfile.LargeZipFile, lambda: [f.write(c) for c in z])
117+
f.close()
118+
except Exception:
119+
raise
120+
finally:
121+
os.remove(f.name)
122+
123+
def test_write_iterable_zip64_with_not_allow_zip64_1_big_file(self):
124+
# check 1 big stream that length require ZIP64 extensions when not allowed zip64
125+
z = zipstream.ZipFile(mode='w', allowZip64=False)
126+
127+
def string_big_generator():
128+
counter = 0
129+
sample = b'zipstream0' * 10000000
130+
len_sample = len(sample)
131+
while counter < zipstream.ZIP64_LIMIT:
132+
counter += len_sample
133+
yield sample
134+
135+
data = [string_big_generator()]
136+
for i, d in enumerate(data):
137+
z.write_iter(iterable=d, arcname='data_{0}'.format(i))
138+
f = tempfile.NamedTemporaryFile(suffix='zip', delete=False)
139+
try:
140+
self.assertRaises(zipfile.LargeZipFile, lambda: [f.write(c) for c in z])
141+
f.close()
142+
except Exception:
143+
raise
144+
finally:
145+
os.remove(f.name)
146+
147+
def test_write_iterable_zip64_with_allow_zip64_many_smalls(self):
148+
# check many small streams that sum length require ZIP64 extensions when allowed zip64
149+
z = zipstream.ZipFile(mode='w', allowZip64=True)
150+
151+
def string_small_generator():
152+
counter = 0
153+
sample = b'zipstream0' * 10000000
154+
len_sample = len(sample)
155+
while counter + len_sample < zipstream.ZIP64_LIMIT:
156+
counter += len_sample
157+
yield sample
158+
159+
data = [string_small_generator(), string_small_generator()]
160+
for i, d in enumerate(data):
161+
z.write_iter(iterable=d, arcname='data_{0}'.format(i))
162+
f = tempfile.NamedTemporaryFile(suffix='zip', delete=False)
163+
try:
164+
for chunk in z:
165+
f.write(chunk)
166+
f.close()
167+
except Exception:
168+
raise
169+
finally:
170+
os.remove(f.name)
171+
172+
def test_write_iterable_zip64_with_allow_zip64_1_big_file(self):
173+
# check 1 big stream that length require ZIP64 extensions when allowed zip64
174+
z = zipstream.ZipFile(mode='w', allowZip64=True)
175+
176+
def string_big_generator():
177+
counter = 0
178+
sample = b'zipstream0' * 10000000
179+
len_sample = len(sample)
180+
while counter < zipstream.ZIP64_LIMIT:
181+
counter += len_sample
182+
yield sample
183+
184+
data = [string_big_generator()]
185+
for i, d in enumerate(data):
186+
z.write_iter(iterable=d, arcname='data_{0}'.format(i))
187+
f = tempfile.NamedTemporaryFile(suffix='zip', delete=False)
188+
try:
189+
for chunk in z:
190+
f.write(chunk)
191+
f.close()
192+
except Exception:
193+
raise
194+
finally:
195+
os.remove(f.name)
196+
197+
99198
if __name__ == '__main__':
100199
unittest.main()

0 commit comments

Comments
 (0)