3
3
4
4
from nose import main
5
5
from nose .tools import *
6
+ from nose .plugins .skip import SkipTest
6
7
7
8
from msgpack import packs , unpacks
8
9
@@ -15,7 +16,7 @@ def testPack():
15
16
0 , 1 , 127 , 128 , 255 , 256 , 65535 , 65536 ,
16
17
- 1 , - 32 , - 33 , - 128 , - 129 , - 32768 , - 32769 ,
17
18
1.0 ,
18
- b "" , b "a" , b "a"* 31 , b "a"* 32 ,
19
+ "" , "a" , "a" * 31 , "a" * 32 ,
19
20
None , True , False ,
20
21
(), ((),), ((), None ,),
21
22
{None : 0 },
@@ -33,36 +34,40 @@ def testPackUnicode():
33
34
assert_equal (re , td )
34
35
35
36
def testPackUTF32 ():
36
- test_data = [
37
- u"" , u"abcd" , (u"defgh" ,), u"Русский текст" ,
38
- ]
39
- for td in test_data :
40
- print (packs (td , encoding = 'utf-32' ))
41
- re = unpacks (packs (td , encoding = 'utf-32' ), encoding = 'utf-32' )
42
- assert_equal (re , td )
37
+ try :
38
+ test_data = [
39
+ u"" , u"abcd" , (u"defgh" ,), u"Русский текст" ,
40
+ ]
41
+ for td in test_data :
42
+ re = unpacks (packs (td , encoding = 'utf-32' ), encoding = 'utf-32' )
43
+ assert_equal (re , td )
44
+ except LookupError :
45
+ raise SkipTest
43
46
44
47
def testPackBytes ():
45
48
test_data = [
46
- b "" , b "abcd" , (b "defgh" ,),
49
+ "" , "abcd" , ("defgh" ,),
47
50
]
48
51
for td in test_data :
49
52
check (td )
50
53
51
54
def testIgnoreUnicodeErrors ():
52
- re = unpacks (packs (b 'abc\xed def' ),
53
- encoding = 'utf-8 ' , unicode_errors = 'ignore' )
55
+ re = unpacks (packs ('abc\xed def' ),
56
+ encoding = 'ascii ' , unicode_errors = 'ignore' )
54
57
assert_equal (re , "abcdef" )
55
58
56
59
@raises (UnicodeDecodeError )
57
60
def testStrictUnicodeUnpack ():
58
- unpacks (packs (b 'abc\xed def' ), encoding = 'utf-8' )
61
+ unpacks (packs ('abc\xed def' ), encoding = 'utf-8' )
59
62
60
63
@raises (UnicodeEncodeError )
61
64
def testStrictUnicodePack ():
62
65
packs (u"abc\xed def" , encoding = 'ascii' , unicode_errors = 'strict' )
63
66
64
67
def testIgnoreErrorsPack ():
65
- re = unpacks (packs (u"abcФФФdef" , encoding = 'ascii' , unicode_errors = 'ignore' ), encoding = 'utf-8' )
68
+ re = unpacks (
69
+ packs (u"abcФФФdef" , encoding = 'ascii' , unicode_errors = 'ignore' ),
70
+ encoding = 'utf-8' )
66
71
assert_equal (re , u"abcdef" )
67
72
68
73
@raises (TypeError )
@@ -71,7 +76,7 @@ def testNoEncoding():
71
76
72
77
def testDecodeBinary ():
73
78
re = unpacks (packs (u"abc" ), encoding = None )
74
- assert_equal (re , b "abc" )
79
+ assert_equal (re , "abc" )
75
80
76
81
if __name__ == '__main__' :
77
82
main ()
0 commit comments