Skip to content

Commit 6bc61b7

Browse files
committed
Remove unneeded zlib dependency for testing
`zipfile.crc32` is internally `zlib.crc32` and fallbacks to `binacsii.crc32` when `zlib.crc32` is not available. Both of them do the same task. `create_zipfile_with_extra_data` only calls `crc32` and does not actually require the decompression method provided by `zlib`. Use `zipfile.crc32` rather than `zlib.crc32` to allow the test to run on platforms without `zlib` support.
1 parent f28ef85 commit 6bc61b7

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

Lib/test/test_zipfile/test_core.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4089,8 +4089,7 @@ def create_zipfile_with_extra_data(self, filename, extra_data_name):
40894089
tag_for_unicode_path = b'\x75\x70'
40904090
version_of_unicode_path = b'\x01'
40914091

4092-
import zlib
4093-
filename_crc = struct.pack('<L', zlib.crc32(filename_encoded))
4092+
filename_crc = struct.pack('<L', zipfile.crc32(filename_encoded))
40944093

40954094
extra_data = version_of_unicode_path + filename_crc + extra_data_name
40964095
tsize = len(extra_data).to_bytes(2, 'little')
@@ -4100,19 +4099,16 @@ def create_zipfile_with_extra_data(self, filename, extra_data_name):
41004099
# add the file to the ZIP archive
41014100
zf.writestr(zip_info, b'Hello World!')
41024101

4103-
@requires_zlib()
41044102
def test_read_zipfile_containing_unicode_path_extra_field(self):
41054103
self.create_zipfile_with_extra_data("이름.txt", "이름.txt".encode("utf-8"))
41064104
with zipfile.ZipFile(TESTFN, "r") as zf:
41074105
self.assertEqual(zf.filelist[0].filename, "이름.txt")
41084106

4109-
@requires_zlib()
41104107
def test_read_zipfile_warning(self):
41114108
self.create_zipfile_with_extra_data("이름.txt", b"")
41124109
with self.assertWarns(UserWarning):
41134110
zipfile.ZipFile(TESTFN, "r").close()
41144111

4115-
@requires_zlib()
41164112
def test_read_zipfile_error(self):
41174113
self.create_zipfile_with_extra_data("이름.txt", b"\xff")
41184114
with self.assertRaises(zipfile.BadZipfile):

0 commit comments

Comments
 (0)