Skip to content

Commit e9c409a

Browse files
hroncokhrnciar
authored andcommitted
00419: pythongh-112769: test_zlib: Fix comparison of ZLIB_RUNTIME_VERSION with non-int suffix (pythonGH-112771) (pythonGH-112774)
zlib-ng defines the version as "1.3.0.zlib-ng". (cherry picked from commit d384813)
1 parent 2f61d80 commit e9c409a

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

Lib/test/test_zlib.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
1919
'requires Decompress.copy()')
2020

2121

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+
2236
class VersionTestCase(unittest.TestCase):
2337

2438
def test_library_version(self):
@@ -445,9 +459,8 @@ def test_flushes(self):
445459
sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH',
446460
'Z_PARTIAL_FLUSH']
447461

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

453466
sync_opt = [getattr(zlib, opt) for opt in sync_opt
@@ -776,16 +789,7 @@ def test_large_unconsumed_tail(self, size):
776789

777790
def test_wbits(self):
778791
# 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)
792+
supports_wbits_0 = ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 3, 5)
789793

790794
co = zlib.compressobj(level=1, wbits=15)
791795
zlib15 = co.compress(HAMLET_SCENE) + co.flush()

0 commit comments

Comments
 (0)