8000 Use py.test instead of nosetests. · overcastcloud/msgpack-python@593c832 · GitHub
[go: up one dir, main page]

Skip to content

Commit 593c832

Browse files
committed
Use py.test instead of nosetests.
1 parent d57e369 commit 593c832

File tree

10 files changed

+78
-135
lines changed

10 files changed

+78
-135
lines changed

test/test_buffer.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4-
from nose import main
5-
from nose.tools import *
64
from msgpack import packb, unpackb
75

6+
87
def test_unpack_buffer():
98
from array import array
109
buf = array('b')
1110
buf.fromstring(packb(('foo', 'bar')))
1211
obj = unpackb(buf, use_list=1)
13-
assert_equal([b'foo', b'bar'], obj)
12+
assert [b'foo', b'bar'] == obj
1413

15-
if __name__ == '__main__':
16-
main()

test/test_case.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4-
from nose import main
5-
from nose.tools import *
64
from msgpack import packb, unpackb
75

86

97
def check(length, obj):
108
v = packb(obj)
11-
assert_equal(len(v), length, "%r length should be %r but get %r" % (obj, length, len(v)))
12-
assert_equal(unpackb(v, use_list=0), obj)
9+
assert len(v) == length, \
10+
"%r length should be %r but get %r" % (obj, length, len(v))
11+
assert unpackb(v, use_list=0) == obj
1312

1413
def test_1():
1514
for o in [None, True, False, 0, 1, (1 << 6), (1 << 7) - 1, -1,
@@ -70,8 +69,8 @@ def test_array32():
7069

7170

7271
def match(obj, buf):
73-
assert_equal(packb(obj), buf)
74-
assert_equal(unpackb(buf, use_list=0), obj)
72+
assert packb(obj) == buf
73+
assert unpackb(buf, use_list=0) == obj
7574

7675
def test_match():
7776
cases = [
@@ -99,7 +98,5 @@ def test_match():
9998
match(v, p)
10099

101100
def test_unicode():
102-
assert_equal(b'foobar', unpackb(packb('foobar'), use_list=1))
101+
assert unpackb(packb('foobar'), use_list=1) == b'foobar'
103102

104-
if __name__ == '__main__':
105-
main()

test/test_except.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4-
from nose.tools import *
4+
from pytest import raises
55
from msgpack import packb, unpackb
66

77
import datetime
@@ -12,28 +12,20 @@ class DummyException(Exception):
1212

1313

1414
def test_raise_on_find_unsupported_value():
15-
assert_raises(TypeError, packb, datetime.datetime.now())
15+
with raises(TypeError):
16+
packb(datetime.datetime.now())
1617

1718

1819
def test_raise_from_object_hook():
1920
def hook(obj):
2021
raise DummyException
21-
assert_raises(DummyException, unpackb, packb({}), object_hook=hook)
22-
assert_raises(DummyException, unpackb, packb({'fizz': 'buzz'}),
23-
object_hook=hook)
24-
assert_raises(DummyException, unpackb, packb({'fizz': 'buzz'}),
25-
object_pairs_hook=hook)
26-
assert_raises(DummyException, unpackb, packb({'fizz': {'buzz': 'spam'}}),
27-
object_hook=hook)
28-
assert_raises(DummyException, unpackb, packb({'fizz': {'buzz': 'spam'}}),
29-
object_pairs_hook=hook)
30-
31-
32-
@raises(ValueError)
33-
def test_invalidvalue():
34-
unpackb(b'\xd9\x97#DL_')
22+
raises(DummyException, unpackb, packb({}), object_hook=hook)
23+
raises(DummyException, unpackb, packb({'fizz': 'buzz'}), object_hook=hook)
24+
raises(DummyException, unpackb, packb({'fizz': 'buzz'}), object_pairs_hook=hook)
25+
raises(DummyException, unpackb, packb({'fizz': {'buzz': 'spam'}}), object_hook=hook)
26+
raises(DummyException, unpackb, packb({'fizz': {'buzz': 'spam'}}), object_pairs_hook=hook)
3527

3628

37-
if __name__ == '__main__':
38-
from nose import main
39-
main()
29+
def test_invalidvalue():
30+
with raises(ValueError):
31+
unpackb(b'\xd9\x97#DL_')

test/test_format.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4-
from nose import main
5-
from nose.tools import *
64
from msgpack import unpackb
75

86
def check(src, should, use_list=0):
9-
assert_equal(unpackb(src, use_list=use_list), should)
7+
assert unpackb(src, use_list=use_list) == should
108

119
def testSimpleValue():
1210
check(b"\x93\xc0\xc2\xc3",
@@ -70,6 +68,3 @@ def testMap():
7068
b"\xdf\x00\x00\x00\x02\xc0\xc2\xc3\xc2",
7169
({}, {None: False}, {True: False, None: False}, {},
7270
{None: False}, {True: False, None: False}))
73-
74-
if __name__ == '__main__':
75-
main()

test/test_obj.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4-
from nose import main
5-
from nose.tools import *
6-
4+
from pytest import raises
75
from msgpack import packb, unpackb
86

97
def _decode_complex(obj):
@@ -19,35 +17,35 @@ def _encode_complex(obj):
1917
def test_encode_hook():
2018
packed = packb([3, 1+2j], default=_encode_complex)
2119
unpacked = unpackb(packed, use_list=1)
22-
eq_(unpacked[1], {b'__complex__': True, b'real': 1, b'imag': 2})
20+
assert unpacked[1] == {b'__complex__': True, b'real': 1, b'imag': 2}
2321

2422
def test_decode_hook():
2523
packed = packb([3, {b'__complex__': True, b'real': 1, b'imag': 2}])
2624
unpacked = unpackb(packed, object_hook=_decode_complex, use_list=1)
27-
eq_(unpacked[1], 1+2j)
25+
assert unpacked[1] == 1+2j
2826

2927
def test_decode_pairs_hook():
3028
packed = packb([3, {1: 2, 3: 4}])
3129
prod_sum = 1 * 2 + 3 * 4
3230
unpacked = unpackb(packed, object_pairs_hook=lambda l: sum(k * v for k, v in l), use_list=1)
33-
eq_(unpacked[1], prod_sum)
31+
assert unpacked[1] == prod_sum
3432

35-
@raises(ValueError)
3633
def test_only_one_obj_hook():
37-
unpackb(b'', object_hook=lambda x: x, object_pairs_hook=lambda x: x)
34+
with raises(ValueError):
35+
unpackb(b'', object_hook=lambda x: x, object_pairs_hook=lambda x: x)
3836

39-
@raises(ValueError)
4037
def test_bad_hook():
41-
packed = packb([3, 1+2j], default=lambda o: o)
42-
unpacked = unpackb(packed, use_list=1)
38+
with raises(ValueError):
39+
packed = packb([3, 1+2j], default=lambda o: o)
40+
unpacked = unpackb(packed, use_list=1)
4341

4442
def _arr_to_str(arr):
4543
return ''.join(str(c) for c in arr)
4644

4745
def test_array_hook():
4846
packed = packb([1,2,3])
4947
unpacked = unpackb(packed, list_hook=_arr_to_str, use_list=1)
50-
eq_(unpacked, '123')
48+
assert unpacked == '123'
5149

5250

5351
class DecodeError(Exception):
@@ -57,18 +55,13 @@ def bad_complex_decoder(o):
5755
raise DecodeError("Ooops!")
5856

5957

60-
@raises(DecodeError)
6158
def test_an_exception_in_objecthook1():
62-
packed = packb({1: {'__complex__': True, 'real': 1, 'imag': 2}})
63-
unpackb(packed, object_hook=bad_complex_decoder)
59+
with raises(DecodeError):
60+
packed = packb({1: {'__complex__': True, 'real': 1, 'imag': 2}})
61+
unpackb(packed, object_hook=bad_complex_decoder)
6462

6563

66-
@raises(DecodeError)
6764
def test_an_exception_in_objecthook2():
68-
packed = packb({1: [{'__complex__': True, 'real': 1, 'imag': 2}]})
69-
unpackb(packed, list_hook=bad_complex_decoder, use_list=1)
70-
71-
72-
73-
if __name__ == '__main__':
74-
main()
65+
with raises(DecodeError):
66+
packed = packb({1: [{'__complex__': True, 'real': 1, 'imag': 2}]})
67+
unpackb(packed, list_hook=bad_complex_decoder, use_list=1)

test/test_pack.py

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33

44
import six
55
import struct
6-
from nose import main
7-
from nose.tools import *
8-
from nose.plugins.skip import SkipTest
6+
from pytest import raises, xfail
97

108
from msgpack import packb, unpackb, Unpacker, Packer
119

1210
from io import BytesIO
1311

1412
def check(data, use_list=False):
1513
re = unpackb(packb(data), use_list=use_list)
16-
assert_equal(re, data)
14+
assert re == data
1715

1816
def testPack():
1917
test_data = [
@@ -35,11 +33,11 @@ def testPackUnicode():
3533
]
3634
for td in test_data:
3735
re = unpackb(packb(td, encoding='utf-8'), use_list=1, encoding='utf-8')
38-
assert_equal(re, td)
36+
assert re == td
3937
packer = Packer(encoding='utf-8')
4038
data = packer.pack(td)
4139
re = Unpacker(BytesIO(data), encoding='utf-8', use_list=1).unpack()
42-
assert_equal(re, td)
40+
assert re == td
4341

4442
def testPackUTF32():
4543
try:
@@ -51,9 +49,9 @@ def testPackUTF32():
5149
]
5250
for td in test_data:
5351
re = unpackb(packb(td, encoding='utf-32'), use_list=1, encoding='utf-32')
54-
assert_equal(re, td)
55-
except LookupError:
56-
raise SkipTest
52+
assert re == td
53+
except LookupError as e:
54+
xfail(e)
5755

5856
def testPackBytes():
5957
test_data = [
@@ -64,31 +62,31 @@ def testPackBytes():
6462

6563
def testIgnoreUnicodeErrors():
6664
re = unpackb(packb(b'abc\xeddef'), encoding='utf-8', unicode_errors='ignore', use_list=1)
67-
assert_equal(re, "abcdef")
65+
assert re == "abcdef"
6866

69-
@raises(UnicodeDecodeError)
7067
def testStrictUnicodeUnpack():
71-
unpackb(packb(b'abc\xeddef'), encoding='utf-8', use_list=1)
68+
with raises(UnicodeDecodeError):
69+
unpackb(packb(b'abc\xeddef'), encoding='utf-8', use_list=1)
7270

73-
@raises(UnicodeEncodeError)
7471
def testStrictUnicodePack():
75-
packb(six.u("abc\xeddef"), encoding='ascii', unicode_errors='strict')
72+
with raises(UnicodeEncodeError):
73+
packb(six.u("abc\xeddef"), encoding='ascii', unicode_errors='strict')
7674

7775
def testIgnoreErrorsPack():
7876
re = unpackb(packb(six.u("abcФФФdef"), encoding='ascii', unicode_errors='ignore'), encoding='utf-8', use_list=1)
79-
assert_equal(re, six.u("abcdef"))
77+
assert re == six.u("abcdef")
8078

81-
@raises(TypeError)
8279
def testNoEncoding():
83-
packb(six.u("abc"), encoding=None)
80+
with raises(TypeError):
81+
packb(six.u("abc"), encoding=None)
8482

8583
def testDecodeBinary():
8684
re = unpackb(packb("abc"), encoding=None, use_list=1)
87-
assert_equal(re, b"abc")
85+
assert re == b"abc"
8886

8987
def testPackFloat():
90-
assert_equal(packb(1.0, use_single_float=True), b'\xca' + struct.pack('>f', 1.0))
91-
assert_equal(packb(1.0, use_single_float=False), b'\xcb' + struct.pack('>d', 1.0))
88+
assert packb(1.0, use_single_float=True) == b'\xca' + struct.pack('>f', 1.0)
89+
assert packb(1.0, use_single_float=False) == b'\xcb' + struct.pack('>d', 1.0)
9290

9391
def testArraySize(sizes=[0, 5, 50, 1000]):
9492
bio = six.BytesIO()
@@ -151,10 +149,10 @@ def keys(self):
151149
def test_odict():
152150
seq = [(b'one', 1), (b'two', 2), (b'three', 3), (b'four', 4)]
153151
od = odict(seq)
154-
assert_equal(unpackb(packb(od), use_list=1), dict(seq))
152+
assert unpackb(packb(od), use_list=1) == dict(seq)
155153
def pair_hook(seq):
156154
return seq
157-
assert_equal(unpackb(packb(od), object_pairs_hook=pair_hook, use_list=1), seq)
155+
assert unpackb(packb(od), object_pairs_hook=pair_hook, use_list=1) == seq
158156

159157

160158
def test_pairlist():
@@ -163,8 +161,3 @@ def test_pairlist():
163161
packed = packer.pack_map_pairs(pairlist)
164162
unpacked = unpackb(packed, object_pairs_hook=list)
165163
assert pairlist == unpacked
166-
167-
168-
169-
if __name__ == '__main__':
170-
main()

test/test_seq.py

Lines changed: 3 additions & 11 deletions
B5C0
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
# coding: utf-8
33

44
import six
5-
from nose import main
6-
from nose.tools import *
7-
85
import io
96
import msgpack
107

@@ -38,13 +35,8 @@ def test_exceeding_unpacker_read_size():
3835

3936
read_count = 0
4037
for idx, o in enumerate(unpacker):
41-
assert_equal(type(o), bytes)
42-
assert_equal(o, gen_binary_data(idx))
38+
assert type(o) == bytes
39+
assert o == gen_binary_data(idx)
4340
read_count += 1
4441

45-
assert_equal(read_count, NUMBER_OF_STRINGS)
46-
47-
48-
if __name__ == '__main__':
49-
main()
50-
#test_exceeding_unpacker_read_size()
42+
assert read_count == NUMBER_OF_STRINGS

0 commit comments

Comments
 (0)
0