Add tests for reset_decompression_context()
import lz4.frame as lz4frame
+import lz4
def test_create_compression_context():
context = lz4frame.create_compression_context()
- assert context != None
+ assert context is not None
def test_create_decompression_context():
context = lz4frame.create_decompression_context()
- assert context != None
+ assert context is not None
+
+def test_reset_decompression_context_1():
+ if lz4.lz4version() >= 10800:
+ context = lz4frame.create_decompression_context()
+ r = lz4frame.reset_decompression_context(context)
+ assert r is None
+ else:
+ pass
+
+def test_reset_decompression_context_2():
+ if lz4.lz4version() >= 10800:
+ c = lz4frame.compress(b'1234', return_bytearray=False)
+ context = lz4frame.create_decompression_context()
+ try:
+ # Simulate an error by passing junk to decompress
+ d = lz4frame.decompress_chunk(context, c[1:3])
+ except:
+ pass
+ r = lz4frame.reset_decompression_context(context)
+ assert r is None
+ # And confirm we can use the context after reset
+ d = lz4frame.decompress_chunk(context, c)
+ assert d == b'1234'
+ else:
+ pass
def test_compress_return_type_1():
r = lz4frame.compress(b'', return_bytearray=False)
@@ -103,3 +129,4 @@ def test_decompress_chunk_return_type_4():
assert isinstance(r, tuple)
assert isinstance(r[0], bytearray)
assert isinstance(r[1], int)
+
