Skip to content

Commit f23a848

Browse files
authored
Merge pull request #4647 from dalinaum/test_zlib
Update test/test_zlib.py from CPython 3.11.2
2 parents 26a3ec9 + 5be22a0 commit f23a848

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Lib/test/test_zlib.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from test.support import import_helper
44
import binascii
55
import copy
6+
import os
67
import pickle
78
import random
89
import sys
@@ -18,6 +19,35 @@
1819
hasattr(zlib.decompressobj(), "copy"),
1920
'requires Decompress.copy()')
2021

22+
# bpo-46623: On s390x, when a hardware accelerator is used, using different
23+
# ways to compress data with zlib can produce different compressed data.
24+
# Simplified test_pair() code:
25+
#
26+
# def func1(data):
27+
# return zlib.compress(data)
28+
#
29+
# def func2(data)
30+
# co = zlib.compressobj()
31+
# x1 = co.compress(data)
32+
# x2 = co.flush()
33+
# return x1 + x2
34+
#
35+
# On s390x if zlib uses a hardware accelerator, func1() creates a single
36+
# "final" compressed block whereas func2() produces 3 compressed blocks (the
37+
# last one is a final block). On other platforms with no accelerator, func1()
38+
# and func2() produce the same compressed data made of a single (final)
39+
# compressed block.
40+
#
41+
# Only the compressed data is different, the decompression returns the original
42+
# data:
43+
#
44+
# zlib.decompress(func1(data)) == zlib.decompress(func2(data)) == data
45+
#
46+
# Make the assumption that s390x always has an accelerator to simplify the skip
47+
# condition. Windows doesn't have os.uname() but it doesn't support s390x.
48+
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
49+
'skipped on s390x')
50+
2151

2252
class VersionTestCase(unittest.TestCase):
2353

@@ -184,6 +214,7 @@ def test_keywords(self):
184214
bufsize=zlib.DEF_BUF_SIZE),
185215
HAMLET_SCENE)
186216

217+
@skip_on_s390x
187218
def test_speech128(self):
188219
# compress more data
189220
data = HAMLET_SCENE * 128
@@ -237,6 +268,7 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
237268
# TODO: RUSTPYTHON
238269
@unittest.expectedFailure
239270
# Test compression object
271+
@skip_on_s390x
240272
def test_pair(self):
241273
# straightforward compress/decompress objects
242274
datasrc = HAMLET_SCENE * 128
@@ -853,6 +885,13 @@ def test_wbits(self):
853885
dco = zlib.decompressobj(32 + 15)
854886
self.assertEqual(dco.decompress(gzip), HAMLET_SCENE)
855887

888+
for wbits in (-15, 15, 31):
889+
with self.subTest(wbits=wbits):
890+
expected = HAMLET_SCENE
891+
actual = zlib.decompress(
892+
zlib.compress(HAMLET_SCENE, wbits=wbits), wbits=wbits
893+
)
894+
self.assertEqual(expected, actual)
856895

857896
def choose_lines(source, number, seed=None, generator=random):
858897
"""Return a list of number lines randomly chosen from the source"""

0 commit comments

Comments
 (0)