Skip to content

Commit

Permalink
00419: pythongh-112769: test_zlib: Fix comparison of ZLIB_RUNTIME_VER…
Browse files Browse the repository at this point in the history
…SION with non-int suffix (pythonGH-112771) (pythonGH-112774)

zlib-ng defines the version as "1.3.0.zlib-ng".
(cherry picked from commit d384813)
  • Loading branch information
hroncok authored and hrnciar committed Mar 20, 2024
1 parent ac8b882 commit f93af5c
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions Lib/test/test_zlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@
'requires Decompress.copy()')


def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
# Register "1.2.3" as "1.2.3.0"
# or "1.2.0-linux","1.2.0.f","1.2.0.f-linux"
v = zlib_version.split('-', 1)[0].split('.')
if len(v) < 4:
v.append('0')
elif not v[-1].isnumeric():
v[-1] = '0'
return tuple(map(int, v))


ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()


class VersionTestCase(unittest.TestCase):

def test_library_version(self):
Expand Down Expand Up @@ -437,9 +451,8 @@ def test_flushes(self):
sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH',
'Z_PARTIAL_FLUSH']

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

sync_opt = [getattr(zlib, opt) for opt in sync_opt
Expand Down Expand Up @@ -768,16 +781,7 @@ def test_large_unconsumed_tail(self, size):

def test_wbits(self):
# wbits=0 only supported since zlib v1.2.3.5
# Register "1.2.3" as "1.2.3.0"
# or "1.2.0-linux","1.2.0.f","1.2.0.f-linux"
v = zlib.ZLIB_RUNTIME_VERSION.split('-', 1)[0].split('.')
if len(v) < 4:
v.append('0')
elif not v[-1].isnumeric():
v[-1] = '0'

v = tuple(map(int, v))
supports_wbits_0 = v >= (1, 2, 3, 5)
supports_wbits_0 = ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 3, 5)

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

0 comments on commit f93af5c

Please sign in to comment.