mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-20 04:13:16 +00:00
Fix warnings in tests.
This commit is contained in:
parent
60df5eadaf
commit
c2a2d417f1
3 changed files with 14 additions and 15 deletions
|
@ -9,7 +9,7 @@ from msgpack import packb, unpackb
|
|||
def check(length, obj):
|
||||
v = packb(obj)
|
||||
assert_equal(len(v), length, "%r length should be %r but get %r" % (obj, length, len(v)))
|
||||
assert_equal(unpackb(v), obj)
|
||||
assert_equal(unpackb(v, use_list=0), obj)
|
||||
|
||||
def test_1():
|
||||
for o in [None, True, False, 0, 1, (1 << 6), (1 << 7) - 1, -1,
|
||||
|
@ -71,7 +71,7 @@ def test_array32():
|
|||
|
||||
def match(obj, buf):
|
||||
assert_equal(packb(obj), buf)
|
||||
assert_equal(unpackb(buf), obj)
|
||||
assert_equal(unpackb(buf, use_list=0), obj)
|
||||
|
||||
def test_match():
|
||||
cases = [
|
||||
|
@ -99,7 +99,7 @@ def test_match():
|
|||
match(v, p)
|
||||
|
||||
def test_unicode():
|
||||
assert_equal(b'foobar', unpackb(packb('foobar')))
|
||||
assert_equal(b'foobar', unpackb(packb('foobar'), use_list=1))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -18,25 +18,25 @@ def _encode_complex(obj):
|
|||
|
||||
def test_encode_hook():
|
||||
packed = packb([3, 1+2j], default=_encode_complex)
|
||||
unpacked = unpackb(packed)
|
||||
unpacked = unpackb(packed, use_list=1)
|
||||
eq_(unpacked[1], {b'__complex__': True, b'real': 1, b'imag': 2})
|
||||
|
||||
def test_decode_hook():
|
||||
packed = packb([3, {b'__complex__': True, b'real': 1, b'imag': 2}])
|
||||
unpacked = unpackb(packed, object_hook=_decode_complex)
|
||||
unpacked = unpackb(packed, object_hook=_decode_complex, use_list=1)
|
||||
eq_(unpacked[1], 1+2j)
|
||||
|
||||
@raises(ValueError)
|
||||
def test_bad_hook():
|
||||
packed = packb([3, 1+2j], default=lambda o: o)
|
||||
unpacked = unpackb(packed)
|
||||
unpacked = unpackb(packed, use_list=1)
|
||||
|
||||
def _arr_to_str(arr):
|
||||
return ''.join(str(c) for c in arr)
|
||||
|
||||
def test_array_hook():
|
||||
packed = packb([1,2,3])
|
||||
unpacked = unpackb(packed, list_hook=_arr_to_str)
|
||||
unpacked = unpackb(packed, list_hook=_arr_to_str, use_list=1)
|
||||
eq_(unpacked, '123')
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -31,14 +31,14 @@ def testPack():
|
|||
|
||||
def testPackUnicode():
|
||||
test_data = [
|
||||
six.u(""), six.u("abcd"), (six.u("defgh"),), six.u("Русский текст"),
|
||||
six.u(""), six.u("abcd"), [six.u("defgh")], six.u("Русский текст"),
|
||||
]
|
||||
for td in test_data:
|
||||
re = unpackb(packb(td, encoding='utf-8'), use_list=0, encoding='utf-8')
|
||||
re = unpackb(packb(td, encoding='utf-8'), use_list=1, encoding='utf-8')
|
||||
assert_equal(re, td)
|
||||
packer = Packer(encoding='utf-8')
|
||||
data = packer.pack(td)
|
||||
re = Unpacker(BytesIO(data), encoding='utf-8').unpack()
|
||||
re = Unpacker(BytesIO(data), encoding='utf-8', use_list=1).unpack()
|
||||
assert_equal(re, td)
|
||||
|
||||
def testPackUTF32():
|
||||
|
@ -63,20 +63,19 @@ def testPackBytes():
|
|||
check(td)
|
||||
|
||||
def testIgnoreUnicodeErrors():
|
||||
re = unpackb(packb(b'abc\xeddef'),
|
||||
encoding='utf-8', unicode_errors='ignore')
|
||||
re = unpackb(packb(b'abc\xeddef'), encoding='utf-8', unicode_errors='ignore', use_list=1)
|
||||
assert_equal(re, "abcdef")
|
||||
|
||||
@raises(UnicodeDecodeError)
|
||||
def testStrictUnicodeUnpack():
|
||||
unpackb(packb(b'abc\xeddef'), encoding='utf-8')
|
||||
unpackb(packb(b'abc\xeddef'), encoding='utf-8', use_list=1)
|
||||
|
||||
@raises(UnicodeEncodeError)
|
||||
def testStrictUnicodePack():
|
||||
packb(six.u("abc\xeddef"), encoding='ascii', unicode_errors='strict')
|
||||
|
||||
def testIgnoreErrorsPack():
|
||||
re = unpackb(packb(six.u("abcФФФdef"), encoding='ascii', unicode_errors='ignore'), encoding='utf-8')
|
||||
re = unpackb(packb(six.u("abcФФФdef"), encoding='ascii', unicode_errors='ignore'), encoding='utf-8', use_list=1)
|
||||
assert_equal(re, six.u("abcdef"))
|
||||
|
||||
@raises(TypeError)
|
||||
|
@ -84,7 +83,7 @@ def testNoEncoding():
|
|||
packb(six.u("abc"), encoding=None)
|
||||
|
||||
def testDecodeBinary():
|
||||
re = unpackb(packb("abc"), encoding=None)
|
||||
re = unpackb(packb("abc"), encoding=None, use_list=1)
|
||||
assert_equal(re, b"abc")
|
||||
|
||||
def testPackFloat():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue