Skip to content

Commit 636f452

Browse files
committed
Fix tests to pass.
1 parent 0b38e86 commit 636f452

4 files changed

Lines changed: 26 additions & 24 deletions

File tree

test/test_pack.py

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

4+
import six
45
from nose import main
56
from nose.tools import *
67
from nose.plugins.skip import SkipTest
@@ -29,7 +30,7 @@ def testPack():
2930

3031
def testPackUnicode():
3132
test_data = [
32-
"", "abcd", ("defgh",), "Русский текст",
33+
six.u(""), six.u("abcd"), (six.u("defgh"),), six.u("Русский текст"),
3334
]
3435
for td in test_data:
3536
re = unpacks(packs(td, encoding='utf-8'), encoding='utf-8')
@@ -42,7 +43,10 @@ def testPackUnicode():
4243
def testPackUTF32():
4344
try:
4445
test_data = [
45-
"", "abcd", ("defgh",), "Русский текст",
46+
six.u(""),
47+
six.u("abcd"),
48+
(six.u("defgh"),),
49+
six.u("Русский текст"),
4650
]
4751
for td in test_data:
4852
re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
@@ -68,15 +72,15 @@ def testStrictUnicodeUnpack():
6872

6973
@raises(UnicodeEncodeError)
7074
def testStrictUnicodePack():
71-
packs("abc\xeddef", encoding='ascii', unicode_errors='strict')
75+
packs(six.u("abc\xeddef"), encoding='ascii', unicode_errors='strict')
7276

7377
def testIgnoreErrorsPack():
74-
re = unpacks(packs("abcФФФdef", encoding='ascii', unicode_errors='ignore'), encoding='utf-8')
75-
assert_equal(re, "abcdef")
78+
re = unpacks(packs(six.u("abcФФФdef"), encoding='ascii', unicode_errors='ignore'), encoding='utf-8')
79+
assert_equal(re, six.u("abcdef"))
7680

7781
@raises(TypeError)
7882
def testNoEncoding():
79-
packs("abc", encoding=None)
83+
packs(six.u("abc"), encoding=None)
8084

8185
def testDecodeBinary():
8286
re = unpacks(packs("abc"), encoding=None)

test/test_seq.py

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

4+
import six
45
from nose import main
56
from nose.tools import *
67

7-
import StringIO
8+
import io
89
import msgpack
910

10-
binarydata = [chr(i) for i in xrange(256)]
11-
binarydata = "".join(binarydata)
11+
binarydata = [chr(i) for i in range(256)]
12+
binarydata = six.b("".join(binarydata))
1213

1314
def gen_binary_data(idx):
1415
data = binarydata[:idx % 300]
1516
return data
1617

1718
def test_exceeding_unpacker_read_size():
18-
dumpf = StringIO.StringIO()
19+
dumpf = io.BytesIO()
1920

2021
packer = msgpack.Packer()
2122

@@ -26,24 +27,24 @@ def test_exceeding_unpacker_read_size():
2627
# 40 ok for read_size=1024, while 50 introduces errors
2728
# 7000 ok for read_size=1024*1024, while 8000 leads to glibc detected *** python: double free or corruption (!prev):
2829

29-
for idx in xrange(NUMBER_OF_STRINGS):
30+
for idx in range(NUMBER_OF_STRINGS):
3031
data = gen_binary_data(idx)
3132
dumpf.write(packer.pack(data))
3233

33-
f = StringIO.StringIO(dumpf.getvalue())
34+
f = io.BytesIO(dumpf.getvalue())
3435
dumpf.close()
3536

3637
unpacker = msgpack.Unpacker(f, read_size=read_size)
3738

3839
read_count = 0
3940
for idx, o in enumerate(unpacker):
40-
assert_equal(type(o), str)
41+
assert_equal(type(o), bytes)
4142
assert_equal(o, gen_binary_data(idx))
4243
read_count += 1
4344

4445
assert_equal(read_count, NUMBER_OF_STRINGS)
4546

4647

4748
if __name__ == '__main__':
48-
# main()
49-
test_exceeding_unpacker_read_size()
49+
main()
50+
#test_exceeding_unpacker_read_size()

test/test_sequnpack.py

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

4-
5-
64
from msgpack import Unpacker
75

86
def test_foobar():
@@ -16,18 +14,16 @@ def test_foobar():
1614
assert unpacker.unpack() == ord(b'r')
1715
try:
1816
o = unpacker.unpack()
19-
print(("Oops!", o))
20-
assert 0
17+
assert 0, "should raise exception"
2118
except StopIteration:
22-
assert 1
23-
else:
24-
assert 0
19+
assert 1, "ok"
20+
2521
unpacker.feed(b'foo')
2622
unpacker.feed(b'bar')
2723

2824
k = 0
29-
for o, e in zip(unpacker, b'foobarbaz'):
30-
assert o == e
25+
for o, e in zip(unpacker, 'foobarbaz'):
26+
assert o == ord(e)
3127
k += 1
3228
assert k == len(b'foobar')
3329

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ envlist = py26,py27,py32
33
[testenv]
44
deps=
55
nose
6+
six
67

78
commands=nosetests -w test

0 commit comments

Comments
 (0)