Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testIgnoreErrorsPack():
re = unpacks(packs("abcФФФdef", encoding='ascii', unicode_errors='ignore'), encoding='utf-8')
assert_equal(re, "abcdef")
@raises(ValueError)
def test_bad_hook():
packed = packs([3, 1+2j], default=lambda o: o)
unpacked = unpacks(packed)
def check(length, obj):
v = packs(obj)
assert_equal(len(v), length, "%r length should be %r but get %r" % (obj, length, len(v)))
assert_equal(unpacks(v), obj)
def check(data):
re = unpacks(packs(data))
assert_equal(re, data)
def test_decode_hook():
packed = packs([3, {b'__complex__': True, b'real': 1, b'imag': 2}])
unpacked = unpacks(packed, object_hook=_decode_complex)
eq_(unpacked[1], 1+2j)
def _check_decode(bytes):
packed = struct.pack("B" * len(bytes), *bytes)
assert msgpack.unpacks(packed) == msgpack_pure.unpacks(packed)
def test_encode_hook():
packed = packs([3, 1+2j], default=_encode_complex)
unpacked = unpacks(packed)
eq_(unpacked[1], {b'__complex__': True, b'real': 1, b'imag': 2})
def check(data):
re = unpacks(packs(data))
assert_equal(re, data)
def _check(obj):
# NOTE:
# msgpack.packs(obj) nad msgpack_pure.packs(obj) are not necessarily
# match because there are some possible variations which type to use
# for integer values (i.e. uint8/int16 for 0xFF).
obj = _list_to_tuple(obj)
assert msgpack_pure.unpacks(msgpack.packs(obj)) == obj
assert msgpack.unpacks(msgpack_pure.packs(obj)) == obj
assert msgpack_pure.unpacks(msgpack_pure.packs(obj)) == obj
def test_unicode():
assert_equal(b'foobar', unpacks(packs('foobar')))