55from nose .tools import *
66from nose .plugins .skip import SkipTest
77
8- from msgpack import packs , unpacks , Packer , Unpacker
8+ from msgpack import packs , unpacks , Unpacker , Packer
99
10- from StringIO import StringIO
10+ from io import BytesIO
1111
1212def check (data ):
1313 re = unpacks (packs (data ))
@@ -18,7 +18,7 @@ def testPack():
1818 0 , 1 , 127 , 128 , 255 , 256 , 65535 , 65536 ,
1919 - 1 , - 32 , - 33 , - 128 , - 129 , - 32768 , - 32769 ,
2020 1.0 ,
21- "" , "a" , "a" * 31 , "a" * 32 ,
21+ b "" , b "a" , b "a"* 31 , b "a"* 32 ,
2222 None , True , False ,
2323 (), ((),), ((), None ,),
2424 {None : 0 },
@@ -29,20 +29,20 @@ def testPack():
2929
3030def testPackUnicode ():
3131 test_data = [
32- u "" , u "abcd" , (u "defgh" ,), u "Русский текст" ,
32+ "" , "abcd" , ("defgh" ,), "Русский текст" ,
3333 ]
3434 for td in test_data :
3535 re = unpacks (packs (td , encoding = 'utf-8' ), encoding = 'utf-8' )
3636 assert_equal (re , td )
3737 packer = Packer (encoding = 'utf-8' )
3838 data = packer .pack (td )
39- re = Unpacker (StringIO (data ), encoding = 'utf-8' ).unpack ()
39+ re = Unpacker (BytesIO (data ), encoding = 'utf-8' ).unpack ()
4040 assert_equal (re , td )
4141
4242def testPackUTF32 ():
4343 try :
4444 test_data = [
45- u "" , u "abcd" , (u "defgh" ,), u "Русский текст" ,
45+ "" , "abcd" , ("defgh" ,), "Русский текст" ,
4646 ]
4747 for td in test_data :
4848 re = unpacks (packs (td , encoding = 'utf-32' ), encoding = 'utf-32' )
@@ -52,37 +52,35 @@ def testPackUTF32():
5252
5353def testPackBytes ():
5454 test_data = [
55- "" , "abcd" , ("defgh" ,),
55+ b "" , b "abcd" , (b "defgh" ,),
5656 ]
5757 for td in test_data :
5858 check (td )
5959
6060def testIgnoreUnicodeErrors ():
61- re = unpacks (packs ('abc\xed def' ),
62- encoding = 'ascii ' , unicode_errors = 'ignore' )
61+ re = unpacks (packs (b 'abc\xed def' ),
62+ encoding = 'utf-8 ' , unicode_errors = 'ignore' )
6363 assert_equal (re , "abcdef" )
6464
6565@raises (UnicodeDecodeError )
6666def testStrictUnicodeUnpack ():
67- unpacks (packs ('abc\xed def' ), encoding = 'utf-8' )
67+ unpacks (packs (b 'abc\xed def' ), encoding = 'utf-8' )
6868
6969@raises (UnicodeEncodeError )
7070def testStrictUnicodePack ():
71- packs (u "abc\xed def" , encoding = 'ascii' , unicode_errors = 'strict' )
71+ packs ("abc\xed def" , encoding = 'ascii' , unicode_errors = 'strict' )
7272
7373def testIgnoreErrorsPack ():
74- re = unpacks (
75- packs (u"abcФФФdef" , encoding = 'ascii' , unicode_errors = 'ignore' ),
76- encoding = 'utf-8' )
77- assert_equal (re , u"abcdef" )
74+ re = unpacks (packs ("abcФФФdef" , encoding = 'ascii' , unicode_errors = 'ignore' ), encoding = 'utf-8' )
75+ assert_equal (re , "abcdef" )
7876
7977@raises (TypeError )
8078def testNoEncoding ():
81- packs (u "abc" , encoding = None )
79+ packs ("abc" , encoding = None )
8280
8381def testDecodeBinary ():
84- re = unpacks (packs (u "abc" ), encoding = None )
85- assert_equal (re , "abc" )
82+ re = unpacks (packs ("abc" ), encoding = None )
83+ assert_equal (re , b "abc" )
8684
8785if __name__ == '__main__' :
8886 main ()
0 commit comments