|
17 | 17 | 'requires Decompress.copy()')
|
18 | 18 |
|
19 | 19 |
|
| 20 | +def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION): |
| 21 | + # Register "1.2.3" as "1.2.3.0" |
| 22 | + # or "1.2.0-linux","1.2.0.f","1.2.0.f-linux" |
| 23 | + v = zlib_version.split('-', 1)[0].split('.') |
| 24 | + if len(v) < 4: |
| 25 | + v.append('0') |
| 26 | + elif not v[-1].isnumeric(): |
| 27 | + v[-1] = '0' |
| 28 | + return tuple(map(int, v)) |
| 29 | + |
| 30 | + |
| 31 | +ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple() |
| 32 | + |
| 33 | + |
20 | 34 | class VersionTestCase(unittest.TestCase):
|
21 | 35 |
|
22 | 36 | def test_library_version(self):
|
@@ -438,9 +452,8 @@ def test_flushes(self):
|
438 | 452 | sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH',
|
439 | 453 | 'Z_PARTIAL_FLUSH']
|
440 | 454 |
|
441 |
| - ver = tuple(int(v) for v in zlib.ZLIB_RUNTIME_VERSION.split('.')) |
442 | 455 | # Z_BLOCK has a known failure prior to 1.2.5.3
|
443 |
| - if ver >= (1, 2, 5, 3): |
| 456 | + if ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 5, 3): |
444 | 457 | sync_opt.append('Z_BLOCK')
|
445 | 458 |
|
446 | 459 | sync_opt = [getattr(zlib, opt) for opt in sync_opt
|
@@ -769,16 +782,7 @@ def test_large_unconsumed_tail(self, size):
|
769 | 782 |
|
770 | 783 | def test_wbits(self):
|
771 | 784 | # wbits=0 only supported since zlib v1.2.3.5
|
772 |
| - # Register "1.2.3" as "1.2.3.0" |
773 |
| - # or "1.2.0-linux","1.2.0.f","1.2.0.f-linux" |
774 |
| - v = zlib.ZLIB_RUNTIME_VERSION.split('-', 1)[0].split('.') |
775 |
| - if len(v) < 4: |
776 |
| - v.append('0') |
777 |
| - elif not v[-1].isnumeric(): |
778 |
| - v[-1] = '0' |
779 |
| - |
780 |
| - v = tuple(map(int, v)) |
781 |
| - supports_wbits_0 = v >= (1, 2, 3, 5) |
| 785 | + supports_wbits_0 = ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 3, 5) |
782 | 786 |
|
783 | 787 | co = zlib.compressobj(level=1, wbits=15)
|
784 | 788 | zlib15 = co.compress(HAMLET_SCENE) + co.flush()
|
|
0 commit comments