33
44import six
55import 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
108from msgpack import packb , unpackb , Unpacker , Packer
119
1210from io import BytesIO
1311
1412def check (data , use_list = False ):
1513 re = unpackb (packb (data ), use_list = use_list )
16- assert_equal ( re , data )
14+ assert re == data
1715
1816def 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
4442def 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
5856def testPackBytes ():
5957 test_data = [
@@ -64,31 +62,31 @@ def testPackBytes():
6462
6563def testIgnoreUnicodeErrors ():
6664 re = unpackb (packb (b'abc\xed def' ), encoding = 'utf-8' , unicode_errors = 'ignore' , use_list = 1 )
67- assert_equal ( re , "abcdef" )
65+ assert re == "abcdef"
6866
69- @raises (UnicodeDecodeError )
7067def testStrictUnicodeUnpack ():
71- unpackb (packb (b'abc\xed def' ), encoding = 'utf-8' , use_list = 1 )
68+ with raises (UnicodeDecodeError ):
69+ unpackb (packb (b'abc\xed def' ), encoding = 'utf-8' , use_list = 1 )
7270
73- @raises (UnicodeEncodeError )
7471def testStrictUnicodePack ():
75- packb (six .u ("abc\xed def" ), encoding = 'ascii' , unicode_errors = 'strict' )
72+ with raises (UnicodeEncodeError ):
73+ packb (six .u ("abc\xed def" ), encoding = 'ascii' , unicode_errors = 'strict' )
7674
7775def 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 )
8279def testNoEncoding ():
83- packb (six .u ("abc" ), encoding = None )
80+ with raises (TypeError ):
81+ packb (six .u ("abc" ), encoding = None )
8482
8583def testDecodeBinary ():
8684 re = unpackb (packb ("abc" ), encoding = None , use_list = 1 )
87- assert_equal ( re , b"abc" )
85+ assert re == b"abc"
8886
8987def 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
9391def testArraySize (sizes = [0 , 5 , 50 , 1000 ]):
9492 bio = six .BytesIO ()
@@ -151,10 +149,10 @@ def keys(self):
151149def 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
160158def 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 ()
0 commit comments