Skip to content

Commit 48f9d3e

Browse files
authored
[3.10] gh-112769: test_zlib: test_zlib: Fix comparison of ZLIB_RUNTIME_VERSION with non-int suffix (GH-112771) (#119565)
[3.10] gh-112769: test_zlib: test_zlib: Fix comparison of ZLIB_RUNTIME_VERSION with non-int suffix 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 c8f868d commit 48f9d3e

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

Lib/test/test_zlib.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
hasattr(zlib.decompressobj(), "copy"),
1919
'requires Decompress.copy()')
2020

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

2235
class VersionTestCase(unittest.TestCase):
2336

@@ -445,9 +458,8 @@ def test_flushes(self):
445458
sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH',
446459
'Z_PARTIAL_FLUSH']
447460

448-
ver = tuple(int(v) for v in zlib.ZLIB_RUNTIME_VERSION.split('.'))
449461
# Z_BLOCK has a known failure prior to 1.2.5.3
450-
if ver >= (1, 2, 5, 3):
462+
if ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 5, 3):
451463
sync_opt.append('Z_BLOCK')
452464

453465
sync_opt = [getattr(zlib, opt) for opt in sync_opt
@@ -776,16 +788,7 @@ def test_large_unconsumed_tail(self, size):
776788

777789
def test_wbits(self):
778790
# wbits=0 only supported since zlib v1.2.3.5
779-
# Register "1.2.3" as "1.2.3.0"
780-
# or "1.2.0-linux","1.2.0.f","1.2.0.f-linux"
781-
v = zlib.ZLIB_RUNTIME_VERSION.split('-', 1)[0].split('.')
782-
if len(v) < 4:
783-
v.append('0')
784-
elif not v[-1].isnumeric():
785-
v[-1] = '0'
786-
787-
v = tuple(map(int, v))
788-
supports_wbits_0 = v >= (1, 2, 3, 5)
791+
supports_wbits_0 = ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 3, 5)
789792

790793
co = zlib.compressobj(level=1, wbits=15)
791794
zlib15 = co.compress(HAMLET_SCENE) + co.flush()
Lines changed: 3 additions & 0 deletions
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)