Remove pytest warnings

This commit is contained in:
Inada Naoki 2019-01-25 20:52:57 +09:00
parent 28b5f46a34
commit 464fe277e1
3 changed files with 27 additions and 11 deletions

View file

@ -7,6 +7,9 @@ from msgpack import packb, unpackb
def test_unpack_buffer():
from array import array
buf = array('b')
try:
buf.frombytes(packb((b'foo', b'bar')))
except AttributeError: # PY2
buf.fromstring(packb((b'foo', b'bar')))
obj = unpackb(buf, use_list=1)
assert [b'foo', b'bar'] == obj

View file

@ -40,6 +40,9 @@ def test_extension_type():
print('default called', obj)
if isinstance(obj, array.array):
typecode = 123 # application specific typecode
try:
data = obj.tobytes()
except AttributeError:
data = obj.tostring()
return ExtType(typecode, data)
raise TypeError("Unknown type object %r" % (obj,))
@ -48,6 +51,9 @@ def test_extension_type():
print('ext_hook called', code, data)
assert code == 123
obj = array.array('d')
try:
obj.frombytes(data)
except AttributeError: # PY2
obj.fromstring(data)
return obj

View file

@ -2,13 +2,15 @@
# coding: utf-8
from __future__ import absolute_import, division, print_function, unicode_literals
from collections import OrderedDict
from io import BytesIO
import struct
import pytest
from pytest import raises, xfail
from msgpack import packb, unpackb, Unpacker, Packer, pack
from collections import OrderedDict
from io import BytesIO
def check(data, use_list=False):
re = unpackb(packb(data), use_list=use_list)
@ -47,6 +49,7 @@ def testPackUTF32(): # deprecated
"Русский текст",
]
for td in test_data:
with pytest.deprecated_call():
re = unpackb(packb(td, encoding='utf-32'), use_list=1, encoding='utf-32')
assert re == td
except LookupError as e:
@ -67,18 +70,22 @@ def testPackByteArrays():
check(td)
def testIgnoreUnicodeErrors(): # deprecated
with pytest.deprecated_call():
re = unpackb(packb(b'abc\xeddef'), encoding='utf-8', unicode_errors='ignore', use_list=1)
assert re == "abcdef"
def testStrictUnicodeUnpack():
with raises(UnicodeDecodeError):
unpackb(packb(b'abc\xeddef'), raw=False, use_list=1)
packed = packb(b'abc\xeddef')
with pytest.raises(UnicodeDecodeError):
unpackb(packed, raw=False, use_list=1)
def testStrictUnicodePack(): # deprecated
with raises(UnicodeEncodeError):
with pytest.deprecated_call():
packb("abc\xeddef", encoding='ascii', unicode_errors='strict')
def testIgnoreErrorsPack(): # deprecated
with pytest.deprecated_call():
re = unpackb(packb("abcФФФdef", encoding='ascii', unicode_errors='ignore'), raw=False, use_list=1)
assert re == "abcdef"