mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-20 04:13:16 +00:00
Fix tests to pass.
This commit is contained in:
parent
0b38e86534
commit
636f4529aa
4 changed files with 26 additions and 24 deletions
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
|
import six
|
||||||
from nose import main
|
from nose import main
|
||||||
from nose.tools import *
|
from nose.tools import *
|
||||||
from nose.plugins.skip import SkipTest
|
from nose.plugins.skip import SkipTest
|
||||||
|
@ -29,7 +30,7 @@ def testPack():
|
||||||
|
|
||||||
def testPackUnicode():
|
def testPackUnicode():
|
||||||
test_data = [
|
test_data = [
|
||||||
"", "abcd", ("defgh",), "Русский текст",
|
six.u(""), six.u("abcd"), (six.u("defgh"),), six.u("Русский текст"),
|
||||||
]
|
]
|
||||||
for td in test_data:
|
for td in test_data:
|
||||||
re = unpacks(packs(td, encoding='utf-8'), encoding='utf-8')
|
re = unpacks(packs(td, encoding='utf-8'), encoding='utf-8')
|
||||||
|
@ -42,7 +43,10 @@ def testPackUnicode():
|
||||||
def testPackUTF32():
|
def testPackUTF32():
|
||||||
try:
|
try:
|
||||||
test_data = [
|
test_data = [
|
||||||
"", "abcd", ("defgh",), "Русский текст",
|
six.u(""),
|
||||||
|
six.u("abcd"),
|
||||||
|
(six.u("defgh"),),
|
||||||
|
six.u("Русский текст"),
|
||||||
]
|
]
|
||||||
for td in test_data:
|
for td in test_data:
|
||||||
re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
|
re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
|
||||||
|
@ -68,15 +72,15 @@ def testStrictUnicodeUnpack():
|
||||||
|
|
||||||
@raises(UnicodeEncodeError)
|
@raises(UnicodeEncodeError)
|
||||||
def testStrictUnicodePack():
|
def testStrictUnicodePack():
|
||||||
packs("abc\xeddef", encoding='ascii', unicode_errors='strict')
|
packs(six.u("abc\xeddef"), encoding='ascii', unicode_errors='strict')
|
||||||
|
|
||||||
def testIgnoreErrorsPack():
|
def testIgnoreErrorsPack():
|
||||||
re = unpacks(packs("abcФФФdef", encoding='ascii', unicode_errors='ignore'), encoding='utf-8')
|
re = unpacks(packs(six.u("abcФФФdef"), encoding='ascii', unicode_errors='ignore'), encoding='utf-8')
|
||||||
assert_equal(re, "abcdef")
|
assert_equal(re, six.u("abcdef"))
|
||||||
|
|
||||||
@raises(TypeError)
|
@raises(TypeError)
|
||||||
def testNoEncoding():
|
def testNoEncoding():
|
||||||
packs("abc", encoding=None)
|
packs(six.u("abc"), encoding=None)
|
||||||
|
|
||||||
def testDecodeBinary():
|
def testDecodeBinary():
|
||||||
re = unpacks(packs("abc"), encoding=None)
|
re = unpacks(packs("abc"), encoding=None)
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
|
import six
|
||||||
from nose import main
|
from nose import main
|
||||||
from nose.tools import *
|
from nose.tools import *
|
||||||
|
|
||||||
import StringIO
|
import io
|
||||||
import msgpack
|
import msgpack
|
||||||
|
|
||||||
binarydata = [chr(i) for i in xrange(256)]
|
binarydata = [chr(i) for i in range(256)]
|
||||||
binarydata = "".join(binarydata)
|
binarydata = six.b("".join(binarydata))
|
||||||
|
|
||||||
def gen_binary_data(idx):
|
def gen_binary_data(idx):
|
||||||
data = binarydata[:idx % 300]
|
data = binarydata[:idx % 300]
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def test_exceeding_unpacker_read_size():
|
def test_exceeding_unpacker_read_size():
|
||||||
dumpf = StringIO.StringIO()
|
dumpf = io.BytesIO()
|
||||||
|
|
||||||
packer = msgpack.Packer()
|
packer = msgpack.Packer()
|
||||||
|
|
||||||
|
@ -26,18 +27,18 @@ def test_exceeding_unpacker_read_size():
|
||||||
# 40 ok for read_size=1024, while 50 introduces errors
|
# 40 ok for read_size=1024, while 50 introduces errors
|
||||||
# 7000 ok for read_size=1024*1024, while 8000 leads to glibc detected *** python: double free or corruption (!prev):
|
# 7000 ok for read_size=1024*1024, while 8000 leads to glibc detected *** python: double free or corruption (!prev):
|
||||||
|
|
||||||
for idx in xrange(NUMBER_OF_STRINGS):
|
for idx in range(NUMBER_OF_STRINGS):
|
||||||
data = gen_binary_data(idx)
|
data = gen_binary_data(idx)
|
||||||
dumpf.write(packer.pack(data))
|
dumpf.write(packer.pack(data))
|
||||||
|
|
||||||
f = StringIO.StringIO(dumpf.getvalue())
|
f = io.BytesIO(dumpf.getvalue())
|
||||||
dumpf.close()
|
dumpf.close()
|
||||||
|
|
||||||
unpacker = msgpack.Unpacker(f, read_size=read_size)
|
unpacker = msgpack.Unpacker(f, read_size=read_size)
|
||||||
|
|
||||||
read_count = 0
|
read_count = 0
|
||||||
for idx, o in enumerate(unpacker):
|
for idx, o in enumerate(unpacker):
|
||||||
assert_equal(type(o), str)
|
assert_equal(type(o), bytes)
|
||||||
assert_equal(o, gen_binary_data(idx))
|
assert_equal(o, gen_binary_data(idx))
|
||||||
read_count += 1
|
read_count += 1
|
||||||
|
|
||||||
|
@ -45,5 +46,5 @@ def test_exceeding_unpacker_read_size():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# main()
|
main()
|
||||||
test_exceeding_unpacker_read_size()
|
#test_exceeding_unpacker_read_size()
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from msgpack import Unpacker
|
from msgpack import Unpacker
|
||||||
|
|
||||||
def test_foobar():
|
def test_foobar():
|
||||||
|
@ -16,18 +14,16 @@ def test_foobar():
|
||||||
assert unpacker.unpack() == ord(b'r')
|
assert unpacker.unpack() == ord(b'r')
|
||||||
try:
|
try:
|
||||||
o = unpacker.unpack()
|
o = unpacker.unpack()
|
||||||
print(("Oops!", o))
|
assert 0, "should raise exception"
|
||||||
assert 0
|
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
assert 1
|
assert 1, "ok"
|
||||||
else:
|
|
||||||
assert 0
|
|
||||||
unpacker.feed(b'foo')
|
unpacker.feed(b'foo')
|
||||||
unpacker.feed(b'bar')
|
unpacker.feed(b'bar')
|
||||||
|
|
||||||
k = 0
|
k = 0
|
||||||
for o, e in zip(unpacker, b'foobarbaz'):
|
for o, e in zip(unpacker, 'foobarbaz'):
|
||||||
assert o == e
|
assert o == ord(e)
|
||||||
k += 1
|
k += 1
|
||||||
assert k == len(b'foobar')
|
assert k == len(b'foobar')
|
||||||
|
|
||||||
|
|
1
tox.ini
1
tox.ini
|
@ -3,5 +3,6 @@ envlist = py26,py27,py32
|
||||||
[testenv]
|
[testenv]
|
||||||
deps=
|
deps=
|
||||||
nose
|
nose
|
||||||
|
six
|
||||||
|
|
||||||
commands=nosetests -w test
|
commands=nosetests -w test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue