Skip to content

Commit 85811ab

Browse files
committed
Simplify tests with data descriptors
1 parent d9824ce commit 85811ab

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

Lib/test/test_zipfile/test_core.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,11 +2503,14 @@ def _generate_local_file_entry(self, arcname, raw_bytes,
25032503
fz = io.BytesIO()
25042504
f = Unseekable(fz) if dd else fz
25052505
cm = (mock.patch.object(struct, 'pack', side_effect=struct_pack_no_dd_sig)
2506-
if not dd_sig else contextlib.nullcontext())
2506+
if dd and not dd_sig else contextlib.nullcontext())
25072507
with zipfile.ZipFile(f, 'w', compression=compression) as zh:
2508-
with cm:
2509-
with zh.open(arcname, 'w', force_zip64=force_zip64) as fh:
2510-
fh.write(raw_bytes)
2508+
with cm, zh.open(arcname, 'w', force_zip64=force_zip64) as fh:
2509+
fh.write(raw_bytes)
2510+
if dd:
2511+
zi = zh.infolist()[0]
2512+
self.assertTrue(zi.flag_bits & zipfile._MASK_USE_DATA_DESCRIPTOR,
2513+
f'data descriptor flag not set: {zi.filename}')
25112514
fz.seek(0)
25122515
return fz.read()
25132516

Lib/test/test_zipfile64.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ def _test_strip_removed_large_file_with_dd(self, f):
192192
zh.writestr(file, data)
193193

194194
with zipfile.ZipFile(f, 'a') as zh:
195-
# make sure data descriptor bit is really set (by making zip file unseekable)
196-
for zi in zh.infolist():
197-
self.assertTrue(zi.flag_bits & 8, f'data descriptor flag not set: {zi.filename}')
198-
199195
zh.remove(file1)
200196
zh.repack()
201197
self.assertIsNone(zh.testzip())
@@ -227,10 +223,6 @@ def _test_strip_removed_large_file_with_dd_no_sig(self, f):
227223
zh.writestr(file, data)
228224

229225
with zipfile.ZipFile(f, 'a') as zh:
230-
# make sure data descriptor bit is really set (by making zip file unseekable)
231-
for zi in zh.infolist():
232-
self.assertTrue(zi.flag_bits & 8, f'data descriptor flag not set: {zi.filename}')
233-
234226
zh.remove(file1)
235227
zh.repack()
236228
self.assertIsNone(zh.testzip())
@@ -261,10 +253,6 @@ def _test_strip_removed_large_file_with_dd_no_sig_by_decompression(self, f, meth
261253
zh.writestr(file, data)
262254

263255
with zipfile.ZipFile(f, 'a') as zh:
264-
# make sure data descriptor bit is really set (by making zip file unseekable)
265-
for zi in zh.infolist():
266-
self.assertTrue(zi.flag_bits & 8, f'data descriptor flag not set: {zi.filename}')
267-
268256
zh.remove(file1)
269257
zh.repack()
270258
self.assertIsNone(zh.testzip())

0 commit comments

Comments
 (0)