diff options
author | Joel Nothman <joel.nothman@gmail.com> | 2012-09-23 19:37:28 +1000 |
---|---|---|
committer | Joel Nothman <joel.nothman@gmail.com> | 2012-09-23 19:37:28 +1000 |
commit | 77942514db0c5a80e9f3f9bcb1e1939ecc8705e6 (patch) | |
tree | d3fdec62e6250cf329284a309dd468f019583d05 /test/test_obj.py | |
parent | b06ed8eb75563111ef88a119f9f7a45e67f61736 (diff) | |
download | msgpack-python-77942514db0c5a80e9f3f9bcb1e1939ecc8705e6.tar.gz |
Implement object_pairs_hook
Diffstat (limited to 'test/test_obj.py')
-rw-r--r-- | test/test_obj.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/test_obj.py b/test/test_obj.py index d155b73..e0d89fc 100644 --- a/test/test_obj.py +++ b/test/test_obj.py @@ -26,6 +26,16 @@ def test_decode_hook(): unpacked = unpackb(packed, object_hook=_decode_complex) eq_(unpacked[1], 1+2j) +def test_decode_pairs_hook(): + packed = packb([3, {1: 2, 3: 4}]) + prod_sum = 1 * 2 + 3 * 4 + unpacked = unpackb(packed, object_pairs_hook=lambda l: sum(k * v for k, v in l)) + eq_(unpacked[1], prod_sum) + +@raises(ValueError) +def test_only_one_obj_hook(): + unpackb('', object_hook=lambda x: x, object_pairs_hook=lambda x: x) + @raises(ValueError) def test_bad_hook(): packed = packb([3, 1+2j], default=lambda o: o) |