8000 (python) make test pass with Python 2.5 · urso/msgpack-python@ff594d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit ff594d7

Browse files
author
inada-n
committed
(python) make test pass with Python 2.5
1 parent 3ffc759 commit ff594d7

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

test/test_pack.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from nose import main
55
from nose.tools import *
6+
from nose.plugins.skip import SkipTest
67

78
from msgpack import packs, unpacks
89

@@ -15,7 +16,7 @@ def testPack():
1516
0, 1, 127, 128, 255, 256, 65535, 65536,
1617
-1, -32, -33, -128, -129, -32768, -32769,
1718
1.0,
18-
b"", b"a", b"a"*31, b"a"*32,
19+
"", "a", "a"*31, "a"*32,
1920
None, True, False,
2021
(), ((),), ((), None,),
2122
{None: 0},
@@ -33,36 +34,40 @@ def testPackUnicode():
3334
assert_equal(re, td)
3435

3536
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
4346

4447
def testPackBytes():
4548
test_data = [
46-
b"", b"abcd", (b"defgh",),
49+
"", "abcd", ("defgh",),
4750
]
4851
for td in test_data:
4952
check(td)
5053

5154
def testIgnoreUnicodeErrors():
52-
re = unpacks(packs(b'abc\xeddef'),
53-
encoding='utf-8', unicode_errors='ignore')
55+
re = unpacks(packs('abc\xeddef'),
56+
encoding='ascii', unicode_errors='ignore')
5457
assert_equal(re, "abcdef")
5558

5659
@raises(UnicodeDecodeError)
5760
def testStrictUnicodeUnpack():
58-
unpacks(packs(b'abc\xeddef'), encoding='utf-8')
61+
unpacks(packs('abc\xeddef'), encoding='utf-8')
5962

6063
@raises(UnicodeEncodeError)
6164
def testStrictUnicodePack():
6265
packs(u"abc\xeddef", encoding='ascii', unicode_errors='strict')
6366

6467
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')
6671
assert_equal(re, u"abcdef")
6772

6873
@raises(TypeError)
@@ -71,7 +76,7 @@ def testNoEncoding():
7176

7277
def testDecodeBinary():
7378
re = unpacks(packs(u"abc"), encoding=None)
74-
assert_equal(re, b"abc")
79+
assert_equal(re, "abc")
7580

7681
if __name__ == '__main__':
7782
main()

test/test_sequnpack.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
def test_foobar():
77
unpacker = Unpacker(read_size=3)
88
unpacker.feed('foobar')
9-
assert unpacker.unpack() == ord(b'f')
10-
assert unpacker.unpack() == ord(b'o')
11-
assert unpacker.unpack() == ord(b'o')
12-
assert unpacker.unpack() == ord(b'b')
13-
assert unpacker.unpack() == ord(b'a')
14-
assert unpacker.unpack() == ord(b'r')
9+
assert unpacker.unpack() == ord('f')
10+
assert unpacker.unpack() == ord('o')
11+
assert unpacker.unpack() == ord('o')
12+
assert unpacker.unpack() == ord('b')
13+
assert unpacker.unpack() == ord('a')
14+
assert unpacker.unpack() == ord('r')
1515
try:
1616
o = unpacker.unpack()
1717
print "Oops!", o
@@ -20,14 +20,14 @@ def test_foobar():
2020
assert 1
2121
else:
2222
assert 0
23-
unpacker.feed(b'foo')
24-
unpacker.feed(b'bar')
23+
unpacker.feed('foo')
24+
unpacker.feed('bar')
2525

2626
k = 0
27-
for o, e in zip(unpacker, b'foobarbaz'):
27+
for o, e in zip(unpacker, 'foobarbaz'):
2828
assert o == ord(e)
2929
k += 1
30-
assert k == len(b'foobar')
30+
assert k == len('foobar')
3131

3232
if __name__ == '__main__':
3333
test_foobar()

0 commit comments

Comments
 (0)
0