diff options
author | INADA Naoki <inada-n@klab.com> | 2012-09-23 02:13:32 +0900 |
---|---|---|
committer | INADA Naoki <inada-n@klab.com> | 2012-09-23 02:13:32 +0900 |
commit | 4d643894a1ab02b0836245b8a456200cac5ae314 (patch) | |
tree | 0d87a61644b61a5d6e9b5313e82e2093d5bd07e7 /test | |
parent | 5b66edaa156c43793b6f68013a738f545885b8d6 (diff) | |
download | msgpack-python-4d643894a1ab02b0836245b8a456200cac5ae314.tar.gz |
Support packing subclass of dict.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_pack.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/test_pack.py b/test/test_pack.py index 85d11a0..b216c46 100644 --- a/test/test_pack.py +++ b/test/test_pack.py @@ -91,5 +91,31 @@ def testPackFloat(): assert_equal(packb(1.0, use_single_float=True), b'\xca' + struct.pack('>f', 1.0)) assert_equal(packb(1.0, use_single_float=False), b'\xcb' + struct.pack('>d', 1.0)) + +class odict(dict): + '''Reimplement OrderedDict to run test on Python 2.6''' + def __init__(self, seq): + self._seq = seq + dict.__init__(self, seq) + + def items(self): + return self._seq[:] + + def iteritems(self): + return iter(self._seq) + + def keys(self): + return [x[0] for x in self._seq] + +def test_odict(): + seq = [(b'one', 1), (b'two', 2), (b'three', 3), (b'four', 4)] + od = odict(seq) + assert_equal(unpackb(packb(od)), dict(seq)) + # After object_pairs_hook is implemented. + #def pair_hook(seq): + # return seq + #assert_equal(unpackb(packb(od), object_pairs_hook=pair_hook), seq) + + if __name__ == '__main__': main() |