8000 Remove pytest warnings · loude/msgpack-python@464fe27 · GitHub
[go: up one dir, main page]

Skip to content

Commit 464fe27

Browse files
committed
Remove pytest warnings
1 parent 28b5f46 commit 464fe27

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

test/test_buffer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
def test_unpack_buffer():
88
from array import array
99
buf = array('b')
10-
buf.fromstring(packb((b'foo', b'bar')))
10+
try:
11+
buf.frombytes(packb((b'foo', b'bar')))
12+
except AttributeError: # PY2
13+
buf.fromstring(packb((b'foo', b'bar')))
1114
obj = unpackb(buf, use_list=1)
1215
assert [b'foo', b'bar'] == obj
1316

test/test_extension.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,21 @@ def default(obj):
4040
print('default called', obj)
4141
if isinstance(obj, array.array):
4242
typecode = 123 # application specific typecode
43-
data = obj.tostring()
43+
try:
44+
data = obj.tobytes()
45+
except AttributeError:
46+
data = obj.tostring()
4447
return ExtType(typecode, data)
4548
raise TypeError("Unknown type object %r" % (obj,))
4649

4750
def ext_hook(code, data):
4851
print('ext_hook called', code, data)
4952
assert code == 123
5053
obj = array.array('d')
51-
obj.fromstring(data)
54+
try:
55+
obj.frombytes(data)
56+
except AttributeError: # PY2
57+
obj.fromstring(data)
5258
return obj
5359

5460
obj = [42, b'hello', array.array('d', [1.1, 2.2, 3.3])]

test/test_pack.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
# coding: utf-8
33
from __future__ import absolute_import, division, print_function, unicode_literals
44

5+
from collections import OrderedDict
6+
from io import BytesIO
57
import struct
8+
9+
import pytest
610
from pytest import raises, xfail
711

812
from msgpack import packb, unpackb, Unpacker, Packer, pack
913

10-
from collections import OrderedDict
11-
from io import BytesIO
1214

1315
def check(data, use_list=False):
1416
re = unpackb(packb(data), use_list=use_list)
@@ -47,7 +49,8 @@ def testPackUTF32(): # deprecated
4749
"Русский текст",
4850
]
4951
for td in test_data:
50-
re = unpackb(packb(td, encoding='utf-32'), use_list=1, encoding='utf-32')
52+
with pytest.deprecated_call():
53+
re = unpackb(packb(td, encoding='utf-32'), use_list=1, encoding='utf-32')
5154
assert re == td
5255
except LookupError as e:
5356
xfail(e)
@@ -67,19 +70,23 @@ def testPackByteArrays():
6770
check(td)
6871

6972
def testIgnoreUnicodeErrors(): # deprecated
70-
re = unpackb(packb(b'abc\xeddef'), encoding='utf-8', unicode_errors='ignore', use_list=1)
73+
with pytest.deprecated_call():
74+
re = unpackb(packb(b'abc\xeddef'), encoding='utf-8', unicode_errors='ignore', use_list=1)
7175
assert re == "abcdef"
7276

7377
def testStrictUnicodeUnpack():
74-
with raises(UnicodeDecodeError):
75-
unpackb(packb(b'abc\xeddef'), raw=False, use_list=1)
78+
packed = packb(b'abc\xeddef')
79+
with pytest.raises(UnicodeDecodeError):
80+
unpackb(packed, raw=False, use_list=1)
7681

7782
def testStrictUnicodePack(): # deprecated
7883
with raises(UnicodeEncodeError):
79-
packb("abc\xeddef", encoding='ascii', unicode_errors='strict')
84+
with pytest.deprecated_call():
85+
packb("abc\xeddef", encoding='ascii', unicode_errors='strict')
8086

8187
def testIgnoreErrorsPack(): # deprecated
82-
re = unpackb(packb("abcФФФdef", encoding='ascii', unicode_errors='ignore'), raw=False, use_list=1)
88+
with pytest.deprecated_call():
89+
re = unpackb(packb("abcФФФdef", encoding='ascii', unicode_errors='ignore'), raw=False, use_list=1)
8390
assert re == "abcdef"
8491

8592
def testDecodeBinary():

0 commit comments

Comments
 (0)
0