mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-11-02 10:30:54 +00:00
(python) make test pass with Python 2.5
This commit is contained in:
parent
3ffc75928b
commit
ff594d71dd
2 changed files with 29 additions and 24 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
from nose import main
|
||||
from nose.tools import *
|
||||
from nose.plugins.skip import SkipTest
|
||||
|
||||
from msgpack import packs, unpacks
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ def testPack():
|
|||
0, 1, 127, 128, 255, 256, 65535, 65536,
|
||||
-1, -32, -33, -128, -129, -32768, -32769,
|
||||
1.0,
|
||||
b"", b"a", b"a"*31, b"a"*32,
|
||||
"", "a", "a"*31, "a"*32,
|
||||
None, True, False,
|
||||
(), ((),), ((), None,),
|
||||
{None: 0},
|
||||
|
|
@ -33,36 +34,40 @@ def testPackUnicode():
|
|||
assert_equal(re, td)
|
||||
|
||||
def testPackUTF32():
|
||||
test_data = [
|
||||
u"", u"abcd", (u"defgh",), u"Русский текст",
|
||||
]
|
||||
for td in test_data:
|
||||
print(packs(td, encoding='utf-32'))
|
||||
re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
|
||||
assert_equal(re, td)
|
||||
try:
|
||||
test_data = [
|
||||
u"", u"abcd", (u"defgh",), u"Русский текст",
|
||||
]
|
||||
for td in test_data:
|
||||
re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
|
||||
assert_equal(re, td)
|
||||
except LookupError:
|
||||
raise SkipTest
|
||||
|
||||
def testPackBytes():
|
||||
test_data = [
|
||||
b"", b"abcd", (b"defgh",),
|
||||
"", "abcd", ("defgh",),
|
||||
]
|
||||
for td in test_data:
|
||||
check(td)
|
||||
|
||||
def testIgnoreUnicodeErrors():
|
||||
re = unpacks(packs(b'abc\xeddef'),
|
||||
encoding='utf-8', unicode_errors='ignore')
|
||||
re = unpacks(packs('abc\xeddef'),
|
||||
encoding='ascii', unicode_errors='ignore')
|
||||
assert_equal(re, "abcdef")
|
||||
|
||||
@raises(UnicodeDecodeError)
|
||||
def testStrictUnicodeUnpack():
|
||||
unpacks(packs(b'abc\xeddef'), encoding='utf-8')
|
||||
unpacks(packs('abc\xeddef'), encoding='utf-8')
|
||||
|
||||
@raises(UnicodeEncodeError)
|
||||
def testStrictUnicodePack():
|
||||
packs(u"abc\xeddef", encoding='ascii', unicode_errors='strict')
|
||||
|
||||
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")
|
||||
|
||||
@raises(TypeError)
|
||||
|
|
@ -71,7 +76,7 @@ def testNoEncoding():
|
|||
|
||||
def testDecodeBinary():
|
||||
re = unpacks(packs(u"abc"), encoding=None)
|
||||
assert_equal(re, b"abc")
|
||||
assert_equal(re, "abc")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue