Test to demonstrate that the default function isn't always called (#133)

This commit is contained in:
Pramukta Kumar 2015-03-17 15:02:40 -04:00
parent b7806a6e6e
commit 2d05b40b03

View file

@ -55,3 +55,22 @@ def test_extension_type():
s = msgpack.packb(obj, default=default) s = msgpack.packb(obj, default=default)
obj2 = msgpack.unpackb(s, ext_hook=ext_hook) obj2 = msgpack.unpackb(s, ext_hook=ext_hook)
assert obj == obj2 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