Fix tests.

This commit is contained in:
Naoki INADA 2009-12-17 17:58:41 +09:00
parent 5cf85a82d3
commit 63b9a876b0
3 changed files with 17 additions and 15 deletions

View File

@ -5,6 +5,7 @@ from nose import main
from nose.tools import *
from msgpack import packs, unpacks
def check(length, obj):
v = packs(obj)
assert_equal(len(v), length, "%r length should be %r but get %r" % (obj, length, len(v)))
@ -54,7 +55,7 @@ def test_raw32():
def check_array(overhead, num):
check(num + overhead, [None] * num)
check(num + overhead, (None,) * num)
def test_fixarray():
check_array(1, 0)
@ -86,9 +87,9 @@ def test_match():
(-129, '\xd1\xff\x7f'),
({1:1}, '\x81\x01\x01'),
(1.0, "\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"),
([], '\x90'),
(range(15),"\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"),
(range(16),"\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"),
((), '\x90'),
(tuple(range(15)),"\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"),
(tuple(range(16)),"\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"),
({}, '\x80'),
(dict([(x,x) for x in range(15)]), '\x8f\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\t\t\n\n\x0b\x0b\x0c\x0c\r\r\x0e\x0e'),
(dict([(x,x) for x in range(16)]), '\xde\x00\x10\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\t\t\n\n\x0b\x0b\x0c\x0c\r\r\x0e\x0e\x0f\x0f'),

View File

@ -10,21 +10,21 @@ def check(src, should):
def testSimpleValue():
check("\x93\xc0\xc2\xc3",
[None, False, True])
(None, False, True,))
def testFixnum():
check("\x92\x93\x00\x40\x7f\x93\xe0\xf0\xff",
[[0,64,127], [-32,-16,-1]]
((0,64,127,), (-32,-16,-1,),)
)
def testFixArray():
check("\x92\x90\x91\x91\xc0",
[[],[[None]]],
((),((None,),),),
)
def testFixRaw():
check("\x94\xa0\xa1a\xa2bc\xa3def",
["", "a", "bc", "def"],
("", "a", "bc", "def",),
)
def testFixMap():
@ -38,25 +38,26 @@ def testUnsignedInt():
"\x99\xcc\x00\xcc\x80\xcc\xff\xcd\x00\x00\xcd\x80\x00"
"\xcd\xff\xff\xce\x00\x00\x00\x00\xce\x80\x00\x00\x00"
"\xce\xff\xff\xff\xff",
[0, 128, 255, 0, 32768, 65535, 0, 2147483648, 4294967295],
(0, 128, 255, 0, 32768, 65535, 0, 2147483648, 4294967295,),
)
def testSignedInt():
check("\x99\xd0\x00\xd0\x80\xd0\xff\xd1\x00\x00\xd1\x80\x00"
"\xd1\xff\xff\xd2\x00\x00\x00\x00\xd2\x80\x00\x00\x00"
"\xd2\xff\xff\xff\xff",
[0, -128, -1, 0, -32768, -1, 0, -2147483648, -1])
(0, -128, -1, 0, -32768, -1, 0, -2147483648, -1,))
def testRaw():
check("\x96\xda\x00\x00\xda\x00\x01a\xda\x00\x02ab\xdb\x00\x00"
"\x00\x00\xdb\x00\x00\x00\x01a\xdb\x00\x00\x00\x02ab",
["", "a", "ab", "", "a", "ab"])
("", "a", "ab", "", "a", "ab"))
def testArray():
check("\x96\xdc\x00\x00\xdc\x00\x01\xc0\xdc\x00\x02\xc2\xc3\xdd\x00"
"\x00\x00\x00\xdd\x00\x00\x00\x01\xc0\xdd\x00\x00\x00\x02"
"\xc2\xc3",
[[], [None], [False,True], [], [None], [False,True]])
((), (None,), (False,True), (), (None,), (False,True))
)
def testMap():
check(
@ -67,8 +68,8 @@ def testMap():
"\xdf\x00\x00\x00\x00"
"\xdf\x00\x00\x00\x01\xc0\xc2"
"\xdf\x00\x00\x00\x02\xc0\xc2\xc3\xc2",
[{}, {None: False}, {True: False, None: False}, {},
{None: False}, {True: False, None: False}])
({}, {None: False}, {True: False, None: False}, {},
{None: False}, {True: False, None: False}))
if __name__ == '__main__':
main()

View File

@ -17,7 +17,7 @@ def testPack():
1.0,
"", "a", "a"*31, "a"*32,
None, True, False,
[], [[]], [[], None],
(), ((),), ((), None,),
{None: 0},
(1<<23),
]