Blame 00419-gh-112769-test_zlib-fix-comparison-of-zlib_runtime_version-with-non-int-suffix-gh-112771-gh-112774.patch

88ba253
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
88ba253
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
88ba253
Date: Tue, 5 Dec 2023 21:02:06 +0100
88ba253
Subject: [PATCH] 00419: gh-112769: test_zlib: Fix comparison of
88ba253
 ZLIB_RUNTIME_VERSION with non-int suffix (GH-112771) (GH-112774)
88ba253
88ba253
zlib-ng defines the version as "1.3.0.zlib-ng".
88ba253
(cherry picked from commit d384813ff18b33280a90b6d2011654528a2b6ad1)
88ba253
---
88ba253
 Lib/test/test_zlib.py | 28 ++++++++++++++++------------
88ba253
 1 file changed, 16 insertions(+), 12 deletions(-)
88ba253
88ba253
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
88ba253
index f828b4c737..21d28c1781 100644
88ba253
--- a/Lib/test/test_zlib.py
88ba253
+++ b/Lib/test/test_zlib.py
88ba253
@@ -17,6 +17,20 @@ requires_Decompress_copy = unittest.skipUnless(
88ba253
         'requires Decompress.copy()')
88ba253
 
88ba253
 
88ba253
+def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
88ba253
+    # Register "1.2.3" as "1.2.3.0"
88ba253
+    # or "1.2.0-linux","1.2.0.f","1.2.0.f-linux"
88ba253
+    v = zlib_version.split('-', 1)[0].split('.')
88ba253
+    if len(v) < 4:
88ba253
+        v.append('0')
88ba253
+    elif not v[-1].isnumeric():
88ba253
+        v[-1] = '0'
88ba253
+    return tuple(map(int, v))
88ba253
+
88ba253
+
88ba253
+ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()
88ba253
+
88ba253
+
88ba253
 class VersionTestCase(unittest.TestCase):
88ba253
 
88ba253
     def test_library_version(self):
88ba253
@@ -438,9 +452,8 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
88ba253
         sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH',
88ba253
                     'Z_PARTIAL_FLUSH']
88ba253
 
88ba253
-        ver = tuple(int(v) for v in zlib.ZLIB_RUNTIME_VERSION.split('.'))
88ba253
         # Z_BLOCK has a known failure prior to 1.2.5.3
88ba253
-        if ver >= (1, 2, 5, 3):
88ba253
+        if ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 5, 3):
88ba253
             sync_opt.append('Z_BLOCK')
88ba253
 
88ba253
         sync_opt = [getattr(zlib, opt) for opt in sync_opt
88ba253
@@ -769,16 +782,7 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
88ba253
 
88ba253
     def test_wbits(self):
88ba253
         # wbits=0 only supported since zlib v1.2.3.5
88ba253
-        # Register "1.2.3" as "1.2.3.0"
88ba253
-        # or "1.2.0-linux","1.2.0.f","1.2.0.f-linux"
88ba253
-        v = zlib.ZLIB_RUNTIME_VERSION.split('-', 1)[0].split('.')
88ba253
-        if len(v) < 4:
88ba253
-            v.append('0')
88ba253
-        elif not v[-1].isnumeric():
88ba253
-            v[-1] = '0'
88ba253
-
88ba253
-        v = tuple(map(int, v))
88ba253
-        supports_wbits_0 = v >= (1, 2, 3, 5)
88ba253
+        supports_wbits_0 = ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 3, 5)
88ba253
 
88ba253
         co = zlib.compressobj(level=1, wbits=15)
88ba253
         zlib15 = co.compress(HAMLET_SCENE) + co.flush()