def __compress_with_data_and_args(self, data, **kwargs): ctx, header = self.__compress_begin(**kwargs) in_raw = BytesIO(data) out = BytesIO(header) out.seek(0, SEEK_END) try: while True: out.write(compress_update(ctx, in_raw.read(1024))) except Lz4FramedNoDataError: pass out.write(compress_end(ctx)) self.assertEqual(decompress(out.getvalue()), data)
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_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"")