Skip to content

Commit 5505b91

Browse files
authored
[3.8] gh-112769: test_zlib: test_zlib: Fix comparison of ZLIB_RUNTIME_VERSION with non-int suffix (GH-112771) (GH-119567)
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 91e3669 commit 5505b91

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

Lib/test/test_zlib.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
hasattr(zlib.decompressobj(), "copy"),
1717
'requires Decompress.copy()')
1818

19+
def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
20+
# Register "1.2.3" as "1.2.3.0"
21+
# or "1.2.0-linux","1.2.0.f","1.2.0.f-linux"
22+
v = zlib_version.split('-', 1)[0].split('.')
23+
if len(v) < 4:
24+
v.append('0')
25+
elif not v[-1].isnumeric():
26+
v[-1] = '0'
27+
return tuple(map(int, v))
28+
29+
30+
ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()
31+
1932

2033
class VersionTestCase(unittest.TestCase):
2134

@@ -438,9 +451,8 @@ def test_flushes(self):
438451
sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH',
439452
'Z_PARTIAL_FLUSH']
440453

441-
ver = tuple(int(v) for v in zlib.ZLIB_RUNTIME_VERSION.split('.'))
442454
# Z_BLOCK has a known failure prior to 1.2.5.3
443-
if ver >= (1, 2, 5, 3):
455+
if ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 5, 3):
444456
sync_opt.append('Z_BLOCK')
445457

446458
sync_opt = [getattr(zlib, opt) for opt in sync_opt
@@ -769,16 +781,7 @@ def test_large_unconsumed_tail(self, size):
769781

770782
def test_wbits(self):
771783
# wbits=0 only supported since zlib v1.2.3.5
772-
# Register "1.2.3" as "1.2.3.0"
773-
# or "1.2.0-linux","1.2.0.f","1.2.0.f-linux"
774-
v = zlib.ZLIB_RUNTIME_VERSION.split('-', 1)[0].split('.')
775-
if len(v) < 4:
776-
v.append('0')
777-
elif not v[-1].isnumeric():
778-
v[-1] = '0'
779-
780-
v = tuple(map(int, v))
781-
supports_wbits_0 = v >= (1, 2, 3, 5)
784+
supports_wbits_0 = ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 3, 5)
782785

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