Skip to content

Commit d384813

Browse files
authored
pythongh-112769: test_zlib: Fix comparison of ZLIB_RUNTIME_VERSION with non-int suffix (pythonGH-112771)
zlib-ng defines the version as "1.3.0.zlib-ng".
1 parent d109f63 commit d384813

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

Lib/test/test_zlib.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
hasattr(zlib.decompressobj(), "copy"),
1919
'requires Decompress.copy()')
2020

21+
22+
def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
23+
# Register "1.2.3" as "1.2.3.0"
24+
# or "1.2.0-linux","1.2.0.f","1.2.0.f-linux"
25+
v = zlib_version.split('-', 1)[0].split('.')
26+
if len(v) < 4:
27+
v.append('0')
28+
elif not v[-1].isnumeric():
29+
v[-1] = '0'
30+
return tuple(map(int, v))
31+
32+
33+
ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()
34+
35+
2136
# bpo-46623: On s390x, when a hardware accelerator is used, using different
2237
# ways to compress data with zlib can produce different compressed data.
2338
# Simplified test_pair() code:
@@ -473,9 +488,8 @@ def test_flushes(self):
473488
sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH',
474489
'Z_PARTIAL_FLUSH']
475490

476-
ver = tuple(int(v) for v in zlib.ZLIB_RUNTIME_VERSION.split('.'))
477491
# Z_BLOCK has a known failure prior to 1.2.5.3
478-
if ver >= (1, 2, 5, 3):
492+
if ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 5, 3):
479493
sync_opt.append('Z_BLOCK')
480494

481495
sync_opt = [getattr(zlib, opt) for opt in sync_opt
@@ -793,16 +807,7 @@ def test_large_unconsumed_tail(self, size):
793807

794808
def test_wbits(self):
795809
# wbits=0 only supported since zlib v1.2.3.5
796-
# Register "1.2.3" as "1.2.3.0"
797-
# or "1.2.0-linux","1.2.0.f","1.2.0.f-linux"
798-
v = zlib.ZLIB_RUNTIME_VERSION.split('-', 1)[0].split('.')
799-
if len(v) < 4:
800-
v.append('0')
801-
elif not v[-1].isnumeric():
802-
v[-1] = '0'
803-
804-
v = tuple(map(int, v))
805-
supports_wbits_0 = v >= (1, 2, 3, 5)
810+
supports_wbits_0 = ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 3, 5)
806811

807812
co = zlib.compressobj(level=1, wbits=15)
808813
zlib15 = co.compress(HAMLET_SCENE) + co.flush()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The tests now correctly compare zlib version when
2+
:const:`zlib.ZLIB_RUNTIME_VERSION` contains non-integer suffixes. For
3+
example zlib-ng defines the version as ``1.3.0.zlib-ng``.

0 commit comments

Comments
 (0)