mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-28 08:04:12 +00:00
Implement object_pairs_hook
This commit is contained in:
parent
b06ed8eb75
commit
77942514db
5 changed files with 61 additions and 22 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue