|
19 | 19 | 'requires Decompress.copy()')
|
20 | 20 |
|
21 | 21 |
|
| 22 | +def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION): |
| 23 | + # Register "1.2.3" as "1.2.3.0" |
| 24 | + # or "1.2.0-linux","1.2.0.f","1.2.0.f-linux" |
| 25 | + v = zlib_version.split('-', 1)[0].split('.') |
| 26 | + if len(v) < 4: |
| 27 | + v.append('0') |
| 28 | + elif not v[-1].isnumeric(): |
| 29 | + v[-1] = '0' |
| 30 | + return tuple(map(int, v)) |
| 31 | + |
| 32 | + |
| 33 | +ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple() |
| 34 | + |
| 35 | + |
22 | 36 | class VersionTestCase(unittest.TestCase):
|
23 | 37 |
|
24 | 38 | def test_library_version(self):
|
@@ -445,9 +459,8 @@ def test_flushes(self):
|
445 | 459 | sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH',
|
446 | 460 | 'Z_PARTIAL_FLUSH']
|
447 | 461 |
|
448 |
| - ver = tuple(int(v) for v in zlib.ZLIB_RUNTIME_VERSION.split('.')) |
449 | 462 | # Z_BLOCK has a known failure prior to 1.2.5.3
|
450 |
| - if ver >= (1, 2, 5, 3): |
| 463 | + if ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 5, 3): |
451 | 464 | sync_opt.append('Z_BLOCK')
|
452 | 465 |
|
453 | 466 | sync_opt = [getattr(zlib, opt) for opt in sync_opt
|
@@ -776,16 +789,7 @@ def test_large_unconsumed_tail(self, size):
|
776 | 789 |
|
777 | 790 | def test_wbits(self):
|
778 | 791 | # wbits=0 only supported since zlib v1.2.3.5
|
779 |
| - # Register "1.2.3" as "1.2.3.0" |
780 |
| - # or "1.2.0-linux","1.2.0.f","1.2.0.f-linux" |
781 |
| - v = zlib.ZLIB_RUNTIME_VERSION.split('-', 1)[0].split('.') |
782 |
| - if len(v) < 4: |
783 |
| - v.append('0') |
784 |
| - elif not v[-1].isnumeric(): |
785 |
| - v[-1] = '0' |
786 |
| - |
787 |
| - v = tuple(map(int, v)) |
788 |
| - supports_wbits_0 = v >= (1, 2, 3, 5) |
| 792 | + supports_wbits_0 = ZLIB_RUNTIME_VERSION_TUPLE >= (1, 2, 3, 5) |
789 | 793 |
|
790 | 794 | co = zlib.compressobj(level=1, wbits=15)
|
791 | 795 | zlib15 = co.compress(HAMLET_SCENE) + co.flush()
|
|
0 commit comments