Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    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'')
Esempio n. 5
0
    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"")
Esempio n. 6
0
    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)
Esempio n. 7
0
 def __compress_begin(self, **kwargs):
     ctx = create_compression_context()
     header = compress_begin(ctx, **kwargs)
     self.assertTrue(7 <= len(header) <= 15)
     return ctx, header
Esempio n. 8
0
 def __compress_begin(self, **kwargs):
     ctx = create_compression_context()
     header = compress_begin(ctx, **kwargs)
     self.assertTrue(7 <= len(header) <= 15)
     return ctx, header