def test_exceptions(): data = c.compress(b'1010101010100000000000000000000000000000000000000000000000000000000011111111111111111111111111111') data = data[0:16] with pytest.raises(Exception) as e: c.decompress(data) assert("decompressor wrote" in str(e).lower() or "corrupt input at" in str(e).lower() or "decompression failed: corrupt input" in str(e).lower()) data = c.compress(b'1010101010100000000000000000000000000000000000000000000000000000000011111111111111111111111111111') data = [data[0:16] for x in (1, 2, 3)] with pytest.raises(Exception) as e: c.decompress_array(data) assert ("decompressor wrote" in str(e).lower() or "corrupt input at" in str(e).lower() or "decompression failed: corrupt input" in str(e).lower())
def test_compress_array_no_parallel(): a = [b'spam', b'egg', b'spamm', b'spammm'] with patch('arctic._compression.clz4', sentinel.clz4), \ patch('arctic._compression.ENABLE_PARALLEL', False), \ patch('arctic._compression.lz4', wraps=lz4) as patch_lz4: assert decompress_array(compress_array(a)) == a assert patch_lz4.compress.call_args_list == [call(x) for x in a] assert patch_lz4.decompress.call_args_list == [call(compress(x)) for x in a]
def test_performance_sequential(n, length): _str = random_string(length) _strarr = [_str for _ in range(n)] now = dt.now() [c.decompress(y) for y in [c.compressHC(x) for x in _strarr]] clz4_time = (dt.now() - now).total_seconds() now = dt.now() c.decompress_array(c.compressHC_array(_strarr)) clz4_time_p = (dt.now() - now).total_seconds() now = dt.now() [lz4_decompress(y) for y in [lz4_compress(x) for x in _strarr]] lz4_time = (dt.now() - now).total_seconds() print() print("LZ4 Test %sx len:%s" % (n, length)) print(" LZ4 HC %s s" % clz4_time) print(" LZ4 HC Parallel %s s" % clz4_time_p) print(" LZ4 %s s" % lz4_time)
def test_compress_array_no_parallel(): a = ["spam", "egg", "spamm", "spammm"] with patch("arctic._compression.clz4", sentinel.clz4), patch("arctic._compression.ENABLE_PARALLEL", False), patch( "arctic._compression.lz4", wraps=lz4 ) as patch_lz4: assert decompress_array(compress_array(a)) == a assert patch_lz4.compress.call_args_list == [call(x) for x in a] assert patch_lz4.decompress.call_args_list == [call(compress(x)) for x in a]
def test_decompress_array(): ll = [('foo%s' % i).encode('ascii') for i in range(100)] assert decompress_array(compress_array(ll)) == ll
def test_decompress_array(): ll = ['foo%s' % i for i in range(100)] assert decompress_array(compress_array(ll)) == ll
def test_arr_zero(): assert [] == c.compressHC_array([]) assert [] == c.decompress_array([])
def test_roundtrip_arrHC(n, length): _strarr = [random_string(length) for _ in range(n)] cstr = c.compressHC_array(_strarr) assert _strarr == c.decompress_array(cstr)