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