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_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_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_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)