Skip to content

Commit 2d05b40

Browse files
committed
Test to demonstrate that the default function isn't always called (#133)
1 parent b7806a6 commit 2d05b40

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/test_extension.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,22 @@ def ext_hook(code, data):
5555
s = msgpack.packb(obj, default=default)
5656
obj2 = msgpack.unpackb(s, ext_hook=ext_hook)
5757
assert obj == obj2
58+
59+
import sys
60+
if sys.version > '3':
61+
long = int
62+
63+
def test_overriding_hooks():
64+
def default(obj):
65+
if isinstance(obj, long):
66+
return {"__type__": "long", "__data__": str(obj)}
67+
else:
68+
return obj
69+
70+
obj = {"testval": long(1823746192837461928374619)}
71+
refobj = {"testval": default(obj["testval"])}
72+
refout = msgpack.packb(refobj)
73+
assert isinstance(refout, (str, bytes))
74+
testout = msgpack.packb(obj, default=default)
75+
76+
assert refout == testout

0 commit comments

Comments
 (0)