mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-19 20:03:16 +00:00
Remove pytest warnings
This commit is contained in:
parent
28b5f46a34
commit
464fe277e1
3 changed files with 27 additions and 11 deletions
|
@ -7,6 +7,9 @@ from msgpack import packb, unpackb
|
||||||
def test_unpack_buffer():
|
def test_unpack_buffer():
|
||||||
from array import array
|
from array import array
|
||||||
buf = array('b')
|
buf = array('b')
|
||||||
|
try:
|
||||||
|
buf.frombytes(packb((b'foo', b'bar')))
|
||||||
|
except AttributeError: # PY2
|
||||||
buf.fromstring(packb((b'foo', b'bar')))
|
buf.fromstring(packb((b'foo', b'bar')))
|
||||||
obj = unpackb(buf, use_list=1)
|
obj = unpackb(buf, use_list=1)
|
||||||
assert [b'foo', b'bar'] == obj
|
assert [b'foo', b'bar'] == obj
|
||||||
|
|
|
@ -40,6 +40,9 @@ def test_extension_type():
|
||||||
print('default called', obj)
|
print('default called', obj)
|
||||||
if isinstance(obj, array.array):
|
if isinstance(obj, array.array):
|
||||||
typecode = 123 # application specific typecode
|
typecode = 123 # application specific typecode
|
||||||
|
try:
|
||||||
|
data = obj.tobytes()
|
||||||
|
except AttributeError:
|
||||||
data = obj.tostring()
|
data = obj.tostring()
|
||||||
return ExtType(typecode, data)
|
return ExtType(typecode, data)
|
||||||
raise TypeError("Unknown type object %r" % (obj,))
|
raise TypeError("Unknown type object %r" % (obj,))
|
||||||
|
@ -48,6 +51,9 @@ def test_extension_type():
|
||||||
print('ext_hook called', code, data)
|
print('ext_hook called', code, data)
|
||||||
assert code == 123
|
assert code == 123
|
||||||
obj = array.array('d')
|
obj = array.array('d')
|
||||||
|
try:
|
||||||
|
obj.frombytes(data)
|
||||||
|
except AttributeError: # PY2
|
||||||
obj.fromstring(data)
|
obj.fromstring(data)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,15 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
|
from io import BytesIO
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
import pytest
|
||||||
from pytest import raises, xfail
|
from pytest import raises, xfail
|
||||||
|
|
||||||
from msgpack import packb, unpackb, Unpacker, Packer, pack
|
from msgpack import packb, unpackb, Unpacker, Packer, pack
|
||||||
|
|
||||||
from collections import OrderedDict
|
|
||||||
from io import BytesIO
|
|
||||||
|
|
||||||
def check(data, use_list=False):
|
def check(data, use_list=False):
|
||||||
re = unpackb(packb(data), use_list=use_list)
|
re = unpackb(packb(data), use_list=use_list)
|
||||||
|
@ -47,6 +49,7 @@ def testPackUTF32(): # deprecated
|
||||||
"Русский текст",
|
"Русский текст",
|
||||||
]
|
]
|
||||||
for td in test_data:
|
for td in test_data:
|
||||||
|
with pytest.deprecated_call():
|
||||||
re = unpackb(packb(td, encoding='utf-32'), use_list=1, encoding='utf-32')
|
re = unpackb(packb(td, encoding='utf-32'), use_list=1, encoding='utf-32')
|
||||||
assert re == td
|
assert re == td
|
||||||
except LookupError as e:
|
except LookupError as e:
|
||||||
|
@ -67,18 +70,22 @@ def testPackByteArrays():
|
||||||
check(td)
|
check(td)
|
||||||
|
|
||||||
def testIgnoreUnicodeErrors(): # deprecated
|
def testIgnoreUnicodeErrors(): # deprecated
|
||||||
|
with pytest.deprecated_call():
|
||||||
re = unpackb(packb(b'abc\xeddef'), encoding='utf-8', unicode_errors='ignore', use_list=1)
|
re = unpackb(packb(b'abc\xeddef'), encoding='utf-8', unicode_errors='ignore', use_list=1)
|
||||||
assert re == "abcdef"
|
assert re == "abcdef"
|
||||||
|
|
||||||
def testStrictUnicodeUnpack():
|
def testStrictUnicodeUnpack():
|
||||||
with raises(UnicodeDecodeError):
|
packed = packb(b'abc\xeddef')
|
||||||
unpackb(packb(b'abc\xeddef'), raw=False, use_list=1)
|
with pytest.raises(UnicodeDecodeError):
|
||||||
|
unpackb(packed, raw=False, use_list=1)
|
||||||
|
|
||||||
def testStrictUnicodePack(): # deprecated
|
def testStrictUnicodePack(): # deprecated
|
||||||
with raises(UnicodeEncodeError):
|
with raises(UnicodeEncodeError):
|
||||||
|
with pytest.deprecated_call():
|
||||||
packb("abc\xeddef", encoding='ascii', unicode_errors='strict')
|
packb("abc\xeddef", encoding='ascii', unicode_errors='strict')
|
||||||
|
|
||||||
def testIgnoreErrorsPack(): # deprecated
|
def testIgnoreErrorsPack(): # deprecated
|
||||||
|
with pytest.deprecated_call():
|
||||||
re = unpackb(packb("abcФФФdef", encoding='ascii', unicode_errors='ignore'), raw=False, use_list=1)
|
re = unpackb(packb("abcФФФdef", encoding='ascii', unicode_errors='ignore'), raw=False, use_list=1)
|
||||||
assert re == "abcdef"
|
assert re == "abcdef"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue