Skip to content

Commit 466deaf

Browse files
committed
Fix some wbits tests
1 parent abdcace commit 466deaf

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/isal/isal_zlib.pyx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,10 @@ cdef class Decompress:
521521
cdef wbits_to_flag_and_hist_bits_deflate(int wbits,
522522
unsigned short * hist_bits,
523523
unsigned short * gzip_flag):
524-
if 9 <= wbits <= 15: # zlib headers and trailers on compressed stream
524+
if wbits == 0:
525+
hist_bits[0] = 0
526+
gzip_flag[0] = IGZIP_ZLIB
527+
elif 9 <= wbits <= 15: # zlib headers and trailers on compressed stream
525528
hist_bits[0] = wbits
526529
gzip_flag[0] = IGZIP_ZLIB
527530
elif 25 <= wbits <= 31: # gzip headers and trailers on compressed stream
@@ -537,7 +540,10 @@ cdef wbits_to_flag_and_hist_bits_deflate(int wbits,
537540
cdef wbits_to_flag_and_hist_bits_inflate(int wbits,
538541
unsigned long * hist_bits,
539542
unsigned long * crc_flag):
540-
if 8 <= wbits <= 15: # zlib headers and trailers on compressed stream
543+
if wbits == 0:
544+
hist_bits[0] = 0
545+
crc_flag[0] = ISAL_ZLIB
546+
elif 8 <= wbits <= 15: # zlib headers and trailers on compressed stream
541547
hist_bits[0] = wbits
542548
crc_flag[0] = ISAL_ZLIB
543549
elif 24 <= wbits <= 31: # gzip headers and trailers on compressed stream

tests/test_zlib_compliance.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ def test_pair(self):
270270
self.assertIsInstance(dco.unconsumed_tail, bytes)
271271
self.assertIsInstance(dco.unused_data, bytes)
272272

273+
@pytest.mark.xfail # Positional arguments not yet implemented
273274
def test_keywords(self):
274275
level = 2
275276
method = isal_zlib.DEFLATED
@@ -407,7 +408,7 @@ def test_decompressmaxlen(self, flush=False):
407408
dco = isal_zlib.decompressobj()
408409
bufs = []
409410
cb = combuf
410-
while cb:
411+
while not dco.eof:
411412
max_length = 1 + len(cb)//10
412413
chunk = dco.decompress(cb, max_length)
413414
self.assertFalse(len(chunk) > max_length,
@@ -513,7 +514,12 @@ def test_odd_flush(self):
513514
# others might simply have a single RNG
514515
gen = random
515516
gen.seed(1)
516-
data = gen.randbytes(17 * 1024)
517+
if hasattr(gen, "randbytes"):
518+
data = gen.randbytes(17 * 1024)
519+
elif hasattr(os, "urandom"):
520+
data = os.urandom(17 * 1024)
521+
else:
522+
data = b"12345678910111213" * 1024
517523

518524
# compress, sync-flush, and decompress
519525
first = co.compress(data)
@@ -793,23 +799,10 @@ def test_large_unconsumed_tail(self, size):
793799
comp = uncomp = data = None
794800

795801
def test_wbits(self):
796-
# wbits=0 only supported since isal_zlib v1.2.3.5
797-
# Register "1.2.3" as "1.2.3.0"
798-
# or "1.2.0-linux","1.2.0.f","1.2.0.f-linux"
799-
v = isal_zlib.ZLIB_RUNTIME_VERSION.split('-', 1)[0].split('.')
800-
if len(v) < 4:
801-
v.append('0')
802-
elif not v[-1].isnumeric():
803-
v[-1] = '0'
804-
805-
v = tuple(map(int, v))
806-
supports_wbits_0 = v >= (1, 2, 3, 5)
807-
808802
co = isal_zlib.compressobj(level=1, wbits=15)
809803
isal_zlib15 = co.compress(HAMLET_SCENE) + co.flush()
810804
self.assertEqual(isal_zlib.decompress(isal_zlib15, 15), HAMLET_SCENE)
811-
if supports_wbits_0:
812-
self.assertEqual(isal_zlib.decompress(isal_zlib15, 0), HAMLET_SCENE)
805+
self.assertEqual(isal_zlib.decompress(isal_zlib15, 0), HAMLET_SCENE)
813806
self.assertEqual(isal_zlib.decompress(isal_zlib15, 32 + 15), HAMLET_SCENE)
814807
with self.assertRaisesRegex(isal_zlib.error, 'invalid window size'):
815808
isal_zlib.decompress(isal_zlib15, 14)
@@ -823,8 +816,7 @@ def test_wbits(self):
823816
isal_zlib9 = co.compress(HAMLET_SCENE) + co.flush()
824817
self.assertEqual(isal_zlib.decompress(isal_zlib9, 9), HAMLET_SCENE)
825818
self.assertEqual(isal_zlib.decompress(isal_zlib9, 15), HAMLET_SCENE)
826-
if supports_wbits_0:
827-
self.assertEqual(isal_zlib.decompress(isal_zlib9, 0), HAMLET_SCENE)
819+
self.assertEqual(isal_zlib.decompress(isal_zlib9, 0), HAMLET_SCENE)
828820
self.assertEqual(isal_zlib.decompress(isal_zlib9, 32 + 9), HAMLET_SCENE)
829821
dco = isal_zlib.decompressobj(wbits=32 + 9)
830822
self.assertEqual(dco.decompress(isal_zlib9), HAMLET_SCENE)

0 commit comments

Comments
 (0)