mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-04-18 23:41:09 +02:00
(python) make test pass with Python 2.5
This commit is contained in:
parent
709d0cc33e
commit
be6d6560a7
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from nose import main
|
from nose import main
|
||||||
from nose.tools import *
|
from nose.tools import *
|
||||||
|
from nose.plugins.skip import SkipTest
|
||||||
|
|
||||||
from msgpack import packs, unpacks
|
from msgpack import packs, unpacks
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ def testPack():
|
|||||||
0, 1, 127, 128, 255, 256, 65535, 65536,
|
0, 1, 127, 128, 255, 256, 65535, 65536,
|
||||||
-1, -32, -33, -128, -129, -32768, -32769,
|
-1, -32, -33, -128, -129, -32768, -32769,
|
||||||
1.0,
|
1.0,
|
||||||
b"", b"a", b"a"*31, b"a"*32,
|
"", "a", "a"*31, "a"*32,
|
||||||
None, True, False,
|
None, True, False,
|
||||||
(), ((),), ((), None,),
|
(), ((),), ((), None,),
|
||||||
{None: 0},
|
{None: 0},
|
||||||
@ -33,36 +34,40 @@ def testPackUnicode():
|
|||||||
assert_equal(re, td)
|
assert_equal(re, td)
|
||||||
|
|
||||||
def testPackUTF32():
|
def testPackUTF32():
|
||||||
|
try:
|
||||||
test_data = [
|
test_data = [
|
||||||
u"", u"abcd", (u"defgh",), u"Русский текст",
|
u"", u"abcd", (u"defgh",), u"Русский текст",
|
||||||
]
|
]
|
||||||
for td in test_data:
|
for td in test_data:
|
||||||
print(packs(td, encoding='utf-32'))
|
|
||||||
re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
|
re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
|
||||||
assert_equal(re, td)
|
assert_equal(re, td)
|
||||||
|
except LookupError:
|
||||||
|
raise SkipTest
|
||||||
|
|
||||||
def testPackBytes():
|
def testPackBytes():
|
||||||
test_data = [
|
test_data = [
|
||||||
b"", b"abcd", (b"defgh",),
|
"", "abcd", ("defgh",),
|
||||||
]
|
]
|
||||||
for td in test_data:
|
for td in test_data:
|
||||||
check(td)
|
check(td)
|
||||||
|
|
||||||
def testIgnoreUnicodeErrors():
|
def testIgnoreUnicodeErrors():
|
||||||
re = unpacks(packs(b'abc\xeddef'),
|
re = unpacks(packs('abc\xeddef'),
|
||||||
encoding='utf-8', unicode_errors='ignore')
|
encoding='ascii', unicode_errors='ignore')
|
||||||
assert_equal(re, "abcdef")
|
assert_equal(re, "abcdef")
|
||||||
|
|
||||||
@raises(UnicodeDecodeError)
|
@raises(UnicodeDecodeError)
|
||||||
def testStrictUnicodeUnpack():
|
def testStrictUnicodeUnpack():
|
||||||
unpacks(packs(b'abc\xeddef'), encoding='utf-8')
|
unpacks(packs('abc\xeddef'), encoding='utf-8')
|
||||||
|
|
||||||
@raises(UnicodeEncodeError)
|
@raises(UnicodeEncodeError)
|
||||||
def testStrictUnicodePack():
|
def testStrictUnicodePack():
|
||||||
packs(u"abc\xeddef", encoding='ascii', unicode_errors='strict')
|
packs(u"abc\xeddef", encoding='ascii', unicode_errors='strict')
|
||||||
|
|
||||||
def testIgnoreErrorsPack():
|
def testIgnoreErrorsPack():
|
||||||
re = unpacks(packs(u"abcФФФdef", encoding='ascii', unicode_errors='ignore'), encoding='utf-8')
|
re = unpacks(
|
||||||
|
packs(u"abcФФФdef", encoding='ascii', unicode_errors='ignore'),
|
||||||
|
encoding='utf-8')
|
||||||
assert_equal(re, u"abcdef")
|
assert_equal(re, u"abcdef")
|
||||||
|
|
||||||
@raises(TypeError)
|
@raises(TypeError)
|
||||||
@ -71,7 +76,7 @@ def testNoEncoding():
|
|||||||
|
|
||||||
def testDecodeBinary():
|
def testDecodeBinary():
|
||||||
re = unpacks(packs(u"abc"), encoding=None)
|
re = unpacks(packs(u"abc"), encoding=None)
|
||||||
assert_equal(re, b"abc")
|
assert_equal(re, "abc")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -6,12 +6,12 @@ from msgpack import Unpacker
|
|||||||
def test_foobar():
|
def test_foobar():
|
||||||
unpacker = Unpacker(read_size=3)
|
unpacker = Unpacker(read_size=3)
|
||||||
unpacker.feed('foobar')
|
unpacker.feed('foobar')
|
||||||
assert unpacker.unpack() == ord(b'f')
|
assert unpacker.unpack() == ord('f')
|
||||||
assert unpacker.unpack() == ord(b'o')
|
assert unpacker.unpack() == ord('o')
|
||||||
assert unpacker.unpack() == ord(b'o')
|
assert unpacker.unpack() == ord('o')
|
||||||
assert unpacker.unpack() == ord(b'b')
|
assert unpacker.unpack() == ord('b')
|
||||||
assert unpacker.unpack() == ord(b'a')
|
assert unpacker.unpack() == ord('a')
|
||||||
assert unpacker.unpack() == ord(b'r')
|
assert unpacker.unpack() == ord('r')
|
||||||
try:
|
try:
|
||||||
o = unpacker.unpack()
|
o = unpacker.unpack()
|
||||||
print "Oops!", o
|
print "Oops!", o
|
||||||
@ -20,14 +20,14 @@ def test_foobar():
|
|||||||
assert 1
|
assert 1
|
||||||
else:
|
else:
|
||||||
assert 0
|
assert 0
|
||||||
unpacker.feed(b'foo')
|
unpacker.feed('foo')
|
||||||
unpacker.feed(b'bar')
|
unpacker.feed('bar')
|
||||||
|
|
||||||
k = 0
|
k = 0
|
||||||
for o, e in zip(unpacker, b'foobarbaz'):
|
for o, e in zip(unpacker, 'foobarbaz'):
|
||||||
assert o == ord(e)
|
assert o == ord(e)
|
||||||
k += 1
|
k += 1
|
||||||
assert k == len(b'foobar')
|
assert k == len('foobar')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_foobar()
|
test_foobar()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user