|
16 | 16 | 'requires Decompress.copy()') |
17 | 17 |
|
18 | 18 |
|
| 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 | + |
19 | 33 | class VersionTestCase(unittest.TestCase): |
20 | 34 |
|
21 | 35 | def test_library_version(self): |
@@ -437,9 +451,8 @@ def test_flushes(self): |
437 | 451 | sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH', |
438 | 452 | 'Z_PARTIAL_FLUSH'] |
439 | 453 |
|
440 | | - ver = tuple(int(v) for v in zlib.ZLIB_RUNTIME_VERSION.split('.')) |
441 | 454 | # 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): |
443 | 456 | sync_opt.append('Z_BLOCK') |
444 | 457 |
|
445 | 458 | sync_opt = [getattr(zlib, opt) for opt in sync_opt |
@@ -762,16 +775,7 @@ def test_large_unconsumed_tail(self, size): |
762 | 775 |
|
763 | 776 | def test_wbits(self): |
764 | 777 | # 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) |
775 | 779 |
|
776 | 780 | co = zlib.compressobj(level=1, wbits=15) |
777 | 781 | zlib15 = co.compress(HAMLET_SCENE) + co.flush() |
|
0 commit comments