Skip to content

Commit 5f220c1

Browse files
committed
Add test for unused data
1 parent ab55226 commit 5f220c1

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/test_isal_zlib.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) 2020 Leiden University Medical Center
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
from isal import isal_zlib
22+
23+
import pytest
24+
25+
26+
@pytest.mark.parametrize("wbits", [-15, 15, 31])
27+
def test_decompress_unused_data(wbits):
28+
"""
29+
Test from CPython's zlib test suite, now improved for all possible modes
30+
raw deflate, zlib and gzip
31+
:return:
32+
"""
33+
source = b'abcdefghijklmnopqrstuvwxyz'
34+
remainder = b'0123456789'
35+
y = isal_zlib.compress(source, wbits=wbits)
36+
x = y + remainder
37+
38+
for maxlen in 0, 1000:
39+
for step in 1, 2, len(y), len(x):
40+
dco = isal_zlib.decompressobj(wbits=wbits)
41+
data = b''
42+
for i in range(0, len(x), step):
43+
if i < len(y):
44+
assert dco.unused_data == b''
45+
if maxlen == 0:
46+
data += dco.decompress(x[i: i + step])
47+
assert dco.unconsumed_tail == b''
48+
else:
49+
data += dco.decompress(
50+
dco.unconsumed_tail + x[i: i + step], maxlen)
51+
data += dco.flush()
52+
assert dco.eof
53+
assert data == source
54+
assert dco.unconsumed_tail == b''
55+
assert dco.unused_data == remainder

0 commit comments

Comments
 (0)