1+ from __future__ import annotations
2+
13import hashlib
24import lzma
35from io import BytesIO
6+ from typing import TYPE_CHECKING
47
58import pytest
69
710from dissect .util .compression import lz4 , lznt1 , lzo , lzxpress , lzxpress_huffman , sevenbit , xz
811
12+ if TYPE_CHECKING :
13+ from pytest_benchmark .fixture import BenchmarkFixture
14+
915
1016def test_lz4_decompress () -> None :
1117 assert (
@@ -26,6 +32,19 @@ def test_lznt1_decompress() -> None:
2632 )
2733
2834
35+ @pytest .mark .benchmark
36+ def test_benchmark_lznt1_decompress (benchmark : BenchmarkFixture ) -> None :
37+ buf = bytes .fromhex (
38+ "38b08846232000204720410010a24701a045204400084501507900c045200524"
39+ "138805b4024a44ef0358028c091601484500be009e000401189000"
40+ )
41+ assert benchmark (lznt1 .decompress , buf ) == (
42+ b"F# F# G A A G F# E D D E F# F# E E F# F# G A A "
43+ b"G F# E D D E F# E D D E E F# D E F# G F# D E F# "
44+ b"G F# E D E A F# F# G A A G F# E D D E F# E D D\x00 "
45+ )
46+
47+
2948def test_lzo_decompress () -> None :
3049 assert (
3150 lzo .decompress (bytes .fromhex ("0361626361626320f314000f616263616263616263616263616263616263110000" ), False )
@@ -231,28 +250,68 @@ def test_lzxpress_huffman_decompress() -> None:
231250 )
232251
233252
253+ @pytest .mark .benchmark
254+ def test_benchmark_lzxpress_huffman_decompress (benchmark : BenchmarkFixture ) -> None :
255+ buf = bytes .fromhex (
256+ "0000000000000000000000000000000000000000000000000000000000000000"
257+ "0000000000000000000000000000000030230000000000000000000000000000"
258+ "0000000000000000000000000000000000000000000000000000000000000000"
259+ "0000000000000000000000000000000000000000000000000000000000000000"
260+ "0200000000000000000000000000002000000000000000000000000000000000"
261+ "0000000000000000000000000000000000000000000000000000000000000000"
262+ "0000000000000000000000000000000000000000000000000000000000000000"
263+ "0000000000000000000000000000000000000000000000000000000000000000"
264+ "a8dc0000ff2601"
265+ )
266+ assert benchmark (lzxpress_huffman .decompress , buf ) == b"abc" * 100
267+
268+
234269def test_lzxpress_decompress () -> None :
235270 assert lzxpress .decompress (bytes .fromhex ("ffff ff1f 6162 6317 000f ff26 01" )) == b"abc" * 100
236271
237272
273+ @pytest .mark .benchmark
274+ def test_benchmark_lzxpress_decompress (benchmark : BenchmarkFixture ) -> None :
275+ buf = bytes .fromhex ("ffff ff1f 6162 6317 000f ff26 01" )
276+ assert benchmark (lzxpress .decompress , buf ) == b"abc" * 100
277+
278+
238279def test_sevenbit_compress () -> None :
239280 result = sevenbit .compress (b"7-bit compression test string" )
240281 target = bytes .fromhex ("b796384d078ddf6db8bc3c9fa7df6e10bd3ca783e67479da7d06" )
241282 assert result == target
242283
243284
285+ @pytest .mark .benchmark
286+ def test_benchmark_sevenbit_compress (benchmark : BenchmarkFixture ) -> None :
287+ buf = b"7-bit compression test string"
288+ assert benchmark (sevenbit .compress , buf ) == bytes .fromhex ("b796384d078ddf6db8bc3c9fa7df6e10bd3ca783e67479da7d06" )
289+
290+
244291def test_sevenbit_decompress () -> None :
245292 result = sevenbit .decompress (bytes .fromhex ("b796384d078ddf6db8bc3c9fa7df6e10bd3ca783e67479da7d06" ))
246293 target = b"7-bit compression test string"
247294 assert result == target
248295
249296
297+ @pytest .mark .benchmark
298+ def test_benchmark_sevenbit_decompress (benchmark : BenchmarkFixture ) -> None :
299+ buf = bytes .fromhex ("b796384d078ddf6db8bc3c9fa7df6e10bd3ca783e67479da7d06" )
300+ assert benchmark (sevenbit .decompress , buf ) == b"7-bit compression test string"
301+
302+
250303def test_sevenbit_decompress_wide () -> None :
251304 result = sevenbit .decompress (bytes .fromhex ("b796384d078ddf6db8bc3c9fa7df6e10bd3ca783e67479da7d06" ), wide = True )
252305 target = "7-bit compression test string" .encode ("utf-16-le" )
253306 assert result == target
254307
255308
309+ @pytest .mark .benchmark
310+ def test_benchmark_sevenbit_decompress_wide (benchmark : BenchmarkFixture ) -> None :
311+ buf = bytes .fromhex ("b796384d078ddf6db8bc3c9fa7df6e10bd3ca783e67479da7d06" )
312+ assert benchmark (sevenbit .decompress , buf , wide = True ) == "7-bit compression test string" .encode ("utf-16-le" )
313+
314+
256315def test_xz_repair_checksum () -> None :
257316 buf = BytesIO (
258317 bytes .fromhex (
0 commit comments