Skip to content

Commit 159d1ad

Browse files
committed
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 ced5fc0 commit 159d1ad

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
@@ -16,6 +16,20 @@
1616
'requires Decompress.copy()')
1717

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+
32+
1933
class VersionTestCase(unittest.TestCase):
2034

2135
def test_library_version(self):
@@ -437,9 +451,8 @@ def test_flushes(self):
437451
sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH',
438452
'Z_PARTIAL_FLUSH']
439453

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

445458
sync_opt = [getattr(zlib, opt) for opt in sync_opt
@@ -762,16 +775,7 @@ def test_large_unconsumed_tail(self, size):
762775

763776
def test_wbits(self):
764777
# wbits=0 only supported since zlib v1.2.3.5
765-
# Register "1.2.3" as "1.2.3.0"
766-
# or "1.2.0-linux","1.2.0.f","1.2.0.f-linux"
767-
v = zlib.ZLIB_RUNTIME_VERSION.split('-', 1)[0].split('.')
768-
if len(v) < 4:
769-
v.append('0')
770-
elif not v[-1].isnumeric():
771-
v[-1] = '0'
772-
773-
v = tuple(map(int, v))
774-
supports_wbits_0 = v >= (1, 2, 3, 5)
778+
supports_wbits_0 = ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 3, 5)
775779

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

0 commit comments

Comments
 (0)