Skip to content

Commit 54b5e9e

Browse files
authored
[3.9] gh-112769: test_zlib: test_zlib: Fix comparison of ZLIB_RUNTIME_VERSION with non-int suffix (GH-112771) (GH-119566)
zlib-ng defines the version as "1.3.0.zlib-ng". (cherry picked from commit d384813) Co-authored-by: Miro Hrončok miro@hroncok.cz
1 parent 5130731 commit 54b5e9e

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

@@ -437,9 +450,8 @@ def test_flushes(self):
437450
sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH',
438451
'Z_PARTIAL_FLUSH']
439452

440-
ver = tuple(int(v) for v in zlib.ZLIB_RUNTIME_VERSION.split('.'))
441453
# Z_BLOCK has a known failure prior to 1.2.5.3
442-
if ver >= (1, 2, 5, 3):
454+
if ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 5, 3):
443455
sync_opt.append('Z_BLOCK')
444456

445457
sync_opt = [getattr(zlib, opt) for opt in sync_opt
@@ -768,16 +780,7 @@ def test_large_unconsumed_tail(self, size):
768780

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

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