Skip to content

Commit 09cb2c2

Browse files
committed
[ci] add additional unittests for zstd and blosc2
1 parent 4f13ec5 commit 09cb2c2

1 file changed

Lines changed: 87 additions & 11 deletions

File tree

python/tests/test_zmat.py

Lines changed: 87 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,48 @@ def test_base64(self):
146146
self._round_trip(self.text, "base64")
147147
self._round_trip(self.mixed, "base64")
148148

149+
def test_zstd(self):
150+
"""Test zstd round-trip on all data types."""
151+
self._round_trip(self.eye5, "zstd")
152+
self._round_trip(self.zeros, "zstd")
153+
self._round_trip(self.text, "zstd")
154+
self._round_trip(self.mixed, "zstd")
155+
156+
def test_blosc2blosclz(self):
157+
"""Test blosc2blosclz round-trip on all data types."""
158+
self._round_trip(self.eye5, "blosc2blosclz")
159+
self._round_trip(self.zeros, "blosc2blosclz")
160+
self._round_trip(self.text, "blosc2blosclz")
161+
self._round_trip(self.mixed, "blosc2blosclz")
162+
163+
def test_blosc2lz4(self):
164+
"""Test blosc2lz4 round-trip on all data types."""
165+
self._round_trip(self.eye5, "blosc2lz4")
166+
self._round_trip(self.zeros, "blosc2lz4")
167+
self._round_trip(self.text, "blosc2lz4")
168+
self._round_trip(self.mixed, "blosc2lz4")
169+
170+
def test_blosc2lz4hc(self):
171+
"""Test blosc2lz4hc round-trip on all data types."""
172+
self._round_trip(self.eye5, "blosc2lz4hc")
173+
self._round_trip(self.zeros, "blosc2lz4hc")
174+
self._round_trip(self.text, "blosc2lz4hc")
175+
self._round_trip(self.mixed, "blosc2lz4hc")
176+
177+
def test_blosc2zlib(self):
178+
"""Test blosc2zlib round-trip on all data types."""
179+
self._round_trip(self.eye5, "blosc2zlib")
180+
self._round_trip(self.zeros, "blosc2zlib")
181+
self._round_trip(self.text, "blosc2zlib")
182+
self._round_trip(self.mixed, "blosc2zlib")
183+
184+
def test_blosc2zstd(self):
185+
"""Test blosc2zstd round-trip on all data types."""
186+
self._round_trip(self.eye5, "blosc2zstd")
187+
self._round_trip(self.zeros, "blosc2zstd")
188+
self._round_trip(self.text, "blosc2zstd")
189+
self._round_trip(self.mixed, "blosc2zstd")
190+
149191
def test_zlib_compresses(self):
150192
"""Test that zlib actually reduces size on compressible data."""
151193
compressed = zmat.compress(self.zeros, method="zlib")
@@ -161,6 +203,16 @@ def test_lz4_compresses(self):
161203
compressed = zmat.compress(self.zeros, method="lz4")
162204
self.assertLess(len(compressed), len(self.zeros))
163205

206+
def test_zstd_compresses(self):
207+
"""Test that zstd actually reduces size on compressible data."""
208+
compressed = zmat.compress(self.zeros, method="zstd")
209+
self.assertLess(len(compressed), len(self.zeros))
210+
211+
def test_blosc2blosclz_compresses(self):
212+
"""Test that blosc2blosclz actually reduces size on compressible data."""
213+
compressed = zmat.compress(self.zeros, method="blosc2blosclz")
214+
self.assertLess(len(compressed), len(self.zeros))
215+
164216

165217
class TestZmatLowLevel(unittest.TestCase):
166218
"""Tests for the low-level zmat.zmat() interface."""
@@ -266,7 +318,7 @@ def _make_sequential(self, n):
266318
def test_large_zeros(self):
267319
"""Test compression of large zero-filled buffer (like zeros(500))."""
268320
data = b"\x00" * (500 * 500 * 8) # 500x500 doubles
269-
for method in ["zlib", "gzip", "lz4", "lzma"]:
321+
for method in ["zlib", "gzip", "lz4", "lzma", "zstd", "blosc2blosclz"]:
270322
compressed = zmat.compress(data, method=method)
271323
self.assertLess(len(compressed), len(data), f"{method} did not compress zeros")
272324
decompressed = zmat.decompress(compressed, method=method)
@@ -275,15 +327,15 @@ def test_large_zeros(self):
275327
def test_large_eye(self):
276328
"""Test compression of identity matrix (like eye(500), mirrors speedbench)."""
277329
data = self._make_eye(500)
278-
for method in ["zlib", "gzip", "lz4", "lz4hc"]:
330+
for method in ["zlib", "gzip", "lz4", "lz4hc", "zstd", "blosc2lz4"]:
279331
compressed = zmat.compress(data, method=method)
280332
decompressed = zmat.decompress(compressed, method=method)
281333
self.assertEqual(decompressed, data, f"{method} round-trip failed on eye(500)")
282334

283335
def test_large_sequential(self):
284336
"""Test compression of sequential data (like magic(500))."""
285337
data = self._make_sequential(500)
286-
for method in ["zlib", "gzip", "lz4", "lzma"]:
338+
for method in ["zlib", "gzip", "lz4", "lzma", "zstd", "blosc2zstd"]:
287339
compressed = zmat.compress(data, method=method)
288340
decompressed = zmat.decompress(compressed, method=method)
289341
self.assertEqual(decompressed, data, f"{method} round-trip failed on sequential data")
@@ -407,27 +459,51 @@ def test_benchmark_eye(self):
407459
row = b"\x00" * (8 * i) + struct.pack("<d", 1.0) + b"\x00" * (8 * (n - i - 1))
408460
data += row
409461

410-
methods = ["zlib", "gzip", "lzma", "lz4", "lz4hc"]
411-
print(f"\n{'Method':<10} {'Size':>8} {'Ratio':>8} {'Comp(s)':>10} {'Decomp(s)':>10}")
412-
print("-" * 50)
462+
methods = [
463+
"zlib",
464+
"gzip",
465+
"lzma",
466+
"lz4",
467+
"lz4hc",
468+
"zstd",
469+
"blosc2blosclz",
470+
"blosc2lz4",
471+
"blosc2lz4hc",
472+
"blosc2zlib",
473+
"blosc2zstd",
474+
]
475+
print(f"\n{'Method':<16} {'Size':>8} {'Ratio':>8} {'Comp(s)':>10} {'Decomp(s)':>10}")
476+
print("-" * 56)
413477
for m in methods:
414478
r = self._benchmark_method(data, m)
415479
print(
416-
f"{r['method']:<10} {r['compressed']:>8} {r['ratio']:>8.4f} "
480+
f"{r['method']:<16} {r['compressed']:>8} {r['ratio']:>8.4f} "
417481
f"{r['compress_time']:>10.6f} {r['decompress_time']:>10.6f}"
418482
)
419483

420484
def test_benchmark_text(self):
421485
"""Benchmark on text data."""
422486
data = b"The quick brown fox jumps over the lazy dog. " * 2000
423487

424-
methods = ["zlib", "gzip", "lzma", "lz4", "lz4hc"]
425-
print(f"\n{'Method':<10} {'Size':>8} {'Ratio':>8} {'Comp(s)':>10} {'Decomp(s)':>10}")
426-
print("-" * 50)
488+
methods = [
489+
"zlib",
490+
"gzip",
491+
"lzma",
492+
"lz4",
493+
"lz4hc",
494+
"zstd",
495+
"blosc2blosclz",
496+
"blosc2lz4",
497+
"blosc2lz4hc",
498+
"blosc2zlib",
499+
"blosc2zstd",
500+
]
501+
print(f"\n{'Method':<16} {'Size':>8} {'Ratio':>8} {'Comp(s)':>10} {'Decomp(s)':>10}")
502+
print("-" * 56)
427503
for m in methods:
428504
r = self._benchmark_method(data, m)
429505
print(
430-
f"{r['method']:<10} {r['compressed']:>8} {r['ratio']:>8.4f} "
506+
f"{r['method']:<16} {r['compressed']:>8} {r['ratio']:>8.4f} "
431507
f"{r['compress_time']:>10.6f} {r['decompress_time']:>10.6f}"
432508
)
433509

0 commit comments

Comments
 (0)