def test_decompress_update_invalid(self): with self.assertRaises(TypeError): decompress_update() with self.assertRaises(TypeError): decompress_update(1) # invalid context with self.assertRaises(ValueError): decompress_update(create_compression_context(), b" ") ctx = create_decompression_context() with self.assertRaises(TypeError): decompress_update(ctx, b" ", chunk_len="1") with self.assertRaises(ValueError): decompress_update(ctx, b" ", chunk_len=0) in_raw = compress(LONG_INPUT, checksum=True) ret = decompress_update(ctx, in_raw[:512], chunk_len=2) # input_hint self.assertTrue(ret.pop() > 0) # chunk length self.assertTrue(len(ret) > 0) self.assertTrue(all(1 <= len(chunk) <= 2 for chunk in ret)) # invalid input (from start of frame) with self.assertRaisesLz4FramedError(LZ4F_ERROR_GENERIC): decompress_update(ctx, in_raw) # checksum invalid in_raw = in_raw[:-4] + b"1234" ctx = create_decompression_context() with self.assertRaisesLz4FramedError(LZ4F_ERROR_contentChecksum_invalid): decompress_update(ctx, in_raw)
def test_decompress_update_invalid(self): with self.assertRaises(TypeError): decompress_update() with self.assertRaises(TypeError): decompress_update(1) # invalid context with self.assertRaises(ValueError): decompress_update(create_compression_context(), b' ') ctx = create_decompression_context() with self.assertRaises(TypeError): decompress_update(ctx, b' ', chunk_len='1') with self.assertRaises(ValueError): decompress_update(ctx, b' ', chunk_len=0) in_raw = compress(LONG_INPUT, checksum=True) ret = decompress_update(ctx, in_raw[:512], chunk_len=2) # input_hint self.assertTrue(ret.pop() > 0) # chunk length self.assertTrue(len(ret) > 0) self.assertTrue(all(1 <= len(chunk) <= 2 for chunk in ret)) # invalid input (from start of frame) with self.assertRaisesLz4FramedError(LZ4F_ERROR_GENERIC): decompress_update(ctx, in_raw) # checksum invalid in_raw = in_raw[:-4] + b'1234' ctx = create_decompression_context() with self.assertRaisesLz4FramedError( LZ4F_ERROR_contentChecksum_invalid): decompress_update(ctx, in_raw)
def test_compress_end(self): with self.assertRaises(TypeError): compress_end() with self.assertRaises(ValueError): compress_end(create_decompression_context()) ctx, header = self.__compress_begin() self.assertEqual(b'', decompress(header + compress_end(ctx))) ctx, header = self.__compress_begin() data = compress_update(ctx, SHORT_INPUT) self.assertEqual(decompress(header + data + compress_end(ctx)), SHORT_INPUT)
def test_compress_end(self): with self.assertRaises(TypeError): compress_end() with self.assertRaises(ValueError): compress_end(create_decompression_context()) ctx, header = self.__compress_begin() # without any compress_update calls frame is invalid with self.assertRaisesLz4FramedError(LZ4F_ERROR_frameHeader_incomplete): decompress(header + compress_end(ctx)) ctx, header = self.__compress_begin() data = compress_update(ctx, SHORT_INPUT) self.assertEqual(decompress(header + data + compress_end(ctx)), SHORT_INPUT)
def test_get_frame_info(self): with self.assertRaises(TypeError): get_frame_info() with self.assertRaises(ValueError): get_frame_info(create_compression_context()) ctx = create_decompression_context() with self.assertRaisesLz4FramedError(LZ4F_ERROR_frameHeader_incomplete): get_frame_info(ctx) # compress with non-default arguments, check info structure args = {"checksum": True, "block_size_id": LZ4F_BLOCKSIZE_MAX256KB, "block_mode_linked": False} # Using long input since lz4 adjusts block size is input smaller than one block decompress_update(ctx, compress(LONG_INPUT, **args)[:15]) info = get_frame_info(ctx) self.assertTrue(info.pop("input_hint", 0) > 0) args["length"] = len(LONG_INPUT) self.assertEqual(info, args)
def test_compress_update_invalid(self): with self.assertRaises(TypeError): compress_update() with self.assertRaises(TypeError): compress_update(1) # invalid context with self.assertRaises(ValueError): compress_update(create_decompression_context(), b' ') # data before compress_begin called with self.assertRaisesLz4FramedError(LZ4F_ERROR_GENERIC): compress_update(create_compression_context(), b' ') ctx, _ = self.__compress_begin() # invalid data with self.assertRaises(TypeError): compress_update(ctx, 1) # empty data with self.assertRaises(Lz4FramedNoDataError): compress_update(ctx, b'')
def test_compress_update_invalid(self): with self.assertRaises(TypeError): compress_update() with self.assertRaises(TypeError): compress_update(1) # invalid context with self.assertRaises(ValueError): compress_update(create_decompression_context(), b" ") # data before compress_begin called with self.assertRaisesLz4FramedError(LZ4F_ERROR_GENERIC): compress_update(create_compression_context(), b" ") ctx, _ = self.__compress_begin() # invalid data with self.assertRaises(TypeError): compress_update(ctx, 1) # empty data with self.assertRaises(Lz4FramedNoDataError): compress_update(ctx, b"")
def test_get_frame_info(self): with self.assertRaises(TypeError): get_frame_info() with self.assertRaises(ValueError): get_frame_info(create_compression_context()) ctx = create_decompression_context() with self.assertRaisesLz4FramedError(LZ4F_ERROR_srcPtr_wrong): get_frame_info(ctx) # compress with non-default arguments, check info structure args = { 'checksum': True, 'block_size_id': LZ4F_BLOCKSIZE_MAX256KB, 'block_mode_linked': False } # Using long input since lz4 adjusts block size is input smaller than one block decompress_update(ctx, compress(LONG_INPUT, **args)[:15]) info = get_frame_info(ctx) self.assertTrue(info.pop('input_hint', 0) > 0) args['length'] = len(LONG_INPUT) self.assertEqual(info, args)
def test_compress_begin(self): with self.assertRaises(TypeError): compress_begin() with self.assertRaises(ValueError): compress_begin(create_decompression_context())
def test_compress_begin(self): with self.assertRaises(TypeError): compress_begin() with self.assertRaises(ValueError): compress_begin(create_decompression_context())
def test_decompress_update_memoryview(self): # pylint: disable=invalid-name ctx = create_decompression_context() data = decompress_update(ctx, memoryview(compress(LONG_INPUT))) self.assertEqual(b''.join(data[:-1]), LONG_INPUT)