Skip to content

Commit 36f6fa4

Browse files
[3.11] gh-112769: test_zlib: Fix comparison of ZLIB_RUNTIME_VERSION with non-int suffix (GH-112771) (GH-112774)
zlib-ng defines the version as "1.3.0.zlib-ng". (cherry picked from commit d384813) Co-authored-by: Miro Hrončok <[email protected]>
1 parent 54ca4c6 commit 36f6fa4

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
@@ -19,6 +19,21 @@
1919
hasattr(zlib.decompressobj(), "copy"),
2020
'requires Decompress.copy()')
2121

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

480-
ver = tuple(int(v) for v in zlib.ZLIB_RUNTIME_VERSION.split('.'))
481495
# Z_BLOCK has a known failure prior to 1.2.5.3
482-
if ver >= (1, 2, 5, 3):
496+
if ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 5, 3):
483497
sync_opt.append('Z_BLOCK')
484498

485499
sync_opt = [getattr(zlib, opt) for opt in sync_opt
@@ -797,16 +811,7 @@ def test_large_unconsumed_tail(self, size):
797811

798812
def test_wbits(self):
799813
# wbits=0 only supported since zlib v1.2.3.5
800-
# Register "1.2.3" as "1.2.3.0"
801-
# or "1.2.0-linux","1.2.0.f","1.2.0.f-linux"
802-
v = zlib.ZLIB_RUNTIME_VERSION.split('-', 1)[0].split('.')
803-
if len(v) < 4:
804-
v.append('0')
805-
elif not v[-1].isnumeric():
806-
v[-1] = '0'
807-
808-
v = tuple(map(int, v))
809-
supports_wbits_0 = v >= (1, 2, 3, 5)
814+
supports_wbits_0 = ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 3, 5)
810815

811816
co = zlib.compressobj(level=1, wbits=15)
812817
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)