diff options
author | Naoki INADA <inada-n@eagle> | 2009-06-29 08:23:27 +0900 |
---|---|---|
committer | Naoki INADA <inada-n@eagle> | 2009-06-29 08:23:27 +0900 |
commit | 0b33a634a668a478ee86f2c3d9d29c6be85afa6b (patch) | |
tree | bb846a0cec902edb4d279f70228a56f42a895a20 /python | |
parent | 3e396ef146940ada28fc8b154189ae9bb206babc (diff) | |
download | msgpack-python-0b33a634a668a478ee86f2c3d9d29c6be85afa6b.tar.gz |
Update test_format.
Diffstat (limited to 'python')
-rw-r--r-- | python/README | 7 | ||||
-rw-r--r-- | python/test/test_format.py | 110 |
2 files changed, 67 insertions, 50 deletions
diff --git a/python/README b/python/README index 12a27b2..243def2 100644 --- a/python/README +++ b/python/README @@ -29,3 +29,10 @@ MessagePack requires gcc currently. So you need to prepare MinGW GCC. $ python setup.py install -c mingw + +TEST +---- +MessagePack uses nosetest for testing. +Run test with following command: + + $ nosetests test diff --git a/python/test/test_format.py b/python/test/test_format.py index a00123c..009a764 100644 --- a/python/test/test_format.py +++ b/python/test/test_format.py @@ -1,64 +1,74 @@ -from unittest import TestCase, main -from msgpack import packs, unpacks +#!/usr/bin/env python +# coding: utf-8 -class TestFormat(TestCase): - def __check(self, obj, expected_packed): - packed = packs(obj) - self.assertEqual(packed, expected_packed) - unpacked = unpacks(packed) - self.assertEqual(unpacked, obj) +from nose import main +from nose.tools import * +from msgpack import unpacks - def testSimpleValues(self): - self.__check(None, '\xc0') - self.__check(True, '\xc3') - self.__check(False, '\xc2') - self.__check( - [None, False, True], - '\x93\xc0\xc2\xc3' - ) +def check(src, should): + assert_equal(unpacks(src), should) - def testFixnum(self): - self.__check( - [[0,64,127], [-32,-16,-1]], - "\x92\x93\x00\x40\x7f\x93\xe0\xf0\xff" - ) - - def testFixArray(self): - self.__check( - [[],[[None]]], - "\x92\x90\x91\x91\xc0" - ) +def testSimpleValue(): + check("\x93\xc0\xc2\xc3", + [None, False, True]) - def testFixRaw(self): - self.__check( - ["", "a", "bc", "def"], - "\x94\xa0\xa1a\xa2bc\xa3def" - ) - pass +def testFixnum(): + check("\x92\x93\x00\x40\x7f\x93\xe0\xf0\xff", + [[0,64,127], [-32,-16,-1]] + ) - def testFixMap(self): - self.__check( - {False: {None: None}, True:{None:{}}}, - "\x82\xc2\x81\xc0\xc0\xc3\x81\xc0\x80" - ) - pass +def testFixArray(): + check("\x92\x90\x91\x91\xc0", + [[],[[None]]], + ) +def testFixRaw(): + check("\x94\xa0\xa1a\xa2bc\xa3def", + ["", "a", "bc", "def"], + ) -class TestUnpack(TestCase): - def __check(self, packed, obj): - self.assertEqual(unpacks(packed), obj) +def testFixMap(): + check( + "\x82\xc2\x81\xc0\xc0\xc3\x81\xc0\x80", + {False: {None: None}, True:{None:{}}}, + ) - def testuint(self): - self.__check( - "\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], - ) +def testUnsignedInt(): + check( + "\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], + ) +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]) +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"]) +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]]) + +def testMap(): + check( + "\x96" + "\xde\x00\x00" + "\xde\x00\x01\xc0\xc2" + "\xde\x00\x02\xc0\xc2\xc3\xc2" + "\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}]) if __name__ == '__main__': main() |