示例#1
0
 def test_snappy_raises_when_not_present(self):
     with patch.object(afkak.codec, 'has_snappy',
                       return_value=False):
         with self.assertRaises(NotImplementedError):
             snappy_encode("Snappy not available")
         with self.assertRaises(NotImplementedError):
             snappy_decode("Snappy not available")
示例#2
0
    def test_snappy_decode_xerial(self):
        header = b'\x82SNAPPY\x00\x00\x00\x00\x01\x00\x00\x00\x01'
        random_snappy = snappy_encode(b'SNAPPY' * 50)
        block_len = len(random_snappy)
        random_snappy2 = snappy_encode(b'XERIAL' * 50)
        block_len2 = len(random_snappy2)

        to_test = header \
            + struct.pack('!i', block_len) + random_snappy \
            + struct.pack('!i', block_len2) + random_snappy2 \

        self.assertEqual(snappy_decode(to_test),
                         (b'SNAPPY' * 50) + (b'XERIAL' * 50))
示例#3
0
    def test_snappy_decode_xerial(self):
        header = b'\x82SNAPPY\x00\x00\x00\x00\x01\x00\x00\x00\x01'
        random_snappy = snappy_encode('SNAPPY' * 50)
        block_len = len(random_snappy)
        random_snappy2 = snappy_encode('XERIAL' * 50)
        block_len2 = len(random_snappy2)

        to_test = header \
            + struct.pack('!i', block_len) + random_snappy \
            + struct.pack('!i', block_len2) + random_snappy2 \

        self.assertEqual(
            snappy_decode(to_test), ('SNAPPY' * 50) + ('XERIAL' * 50))
示例#4
0
    def test_snappy_encode_xerial(self):
        to_ensure = b'\x82SNAPPY\x00\x00\x00\x00\x01\x00\x00\x00\x01' + \
            '\x00\x00\x00\x18' + \
            '\xac\x02\x14SNAPPY\xfe\x06\x00\xfe\x06' + \
            '\x00\xfe\x06\x00\xfe\x06\x00\x96\x06\x00' + \
            '\x00\x00\x00\x18' + \
            '\xac\x02\x14XERIAL\xfe\x06\x00\xfe\x06\x00' + \
            '\xfe\x06\x00\xfe\x06\x00\x96\x06\x00'

        to_test = ('SNAPPY' * 50) + ('XERIAL' * 50)

        compressed = snappy_encode(
            to_test, xerial_compatible=True, xerial_blocksize=300)
        self.assertEqual(compressed, to_ensure)
示例#5
0
    def test_snappy_detect_xerial(self):
        import afkak as afkak1
        _detect_xerial_stream = afkak1.codec._detect_xerial_stream

        header = (b'\x82SNAPPY\x00\x00\x00\x00'
                  '\x01\x00\x00\x00\x01Some extra bytes')
        false_header = b'\x01SNAPPY\x00\x00\x00\x01\x00\x00\x00\x01'
        random_snappy = snappy_encode('SNAPPY' * 50)
        short_data = b'\x01\x02\x03\x04'

        self.assertTrue(_detect_xerial_stream(header))
        self.assertFalse(_detect_xerial_stream(b''))
        self.assertFalse(_detect_xerial_stream(b'\x00'))
        self.assertFalse(_detect_xerial_stream(false_header))
        self.assertFalse(_detect_xerial_stream(random_snappy))
        self.assertFalse(_detect_xerial_stream(short_data))
示例#6
0
 def test_snappy(self):
     for i in range(100):
         s1 = os.urandom(120)
         s2 = snappy_decode(snappy_encode(s1))
         self.assertEqual(s1, s2)
示例#7
0
 def test_snappy(self):
     for i in xrange(100):
         s1 = random_string(120)
         s2 = snappy_decode(snappy_encode(s1))
         self.assertEqual(s1, s2)
示例#8
0
文件: test_codec.py 项目: ciena/afkak
 def test_snappy(self):
     for _i in range(100):
         s1 = os.urandom(120)
         s2 = snappy_decode(snappy_encode(s1))
         self.assertEqual(s1, s2)