mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-19 20:03:16 +00:00
Test to demonstrate that the default function isn't always called (#133)
This commit is contained in:
parent
b7806a6e6e
commit
2d05b40b03
1 changed files with 19 additions and 0 deletions
|
@ -55,3 +55,22 @@ def test_extension_type():
|
|||
s = msgpack.packb(obj, default=default)
|
||||
obj2 = msgpack.unpackb(s, ext_hook=ext_hook)
|
||||
assert obj == obj2
|
||||
|
||||
import sys
|
||||
if sys.version > '3':
|
||||
long = int
|
||||
|
||||
def test_overriding_hooks():
|
||||
def default(obj):
|
||||
if isinstance(obj, long):
|
||||
return {"__type__": "long", "__data__": str(obj)}
|
||||
else:
|
||||
return obj
|
||||
|
||||
obj = {"testval": long(1823746192837461928374619)}
|
||||
refobj = {"testval": default(obj["testval"])}
|
||||
refout = msgpack.packb(refobj)
|
||||
assert isinstance(refout, (str, bytes))
|
||||
testout = msgpack.packb(obj, default=default)
|
||||
|
||||
assert refout == testout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue