Skip to content

Commit a779b79

Browse files
committed
Add test for strict_types option
1 parent 628c519 commit a779b79

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/test_stricttype.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# coding: utf-8
2+
3+
from collections import namedtuple
4+
from msgpack import packb, unpackb
5+
6+
7+
def test_namedtuple():
8+
T = namedtuple('T', "foo bar")
9+
def default(o):
10+
if isinstance(o, T):
11+
return dict(o._asdict())
12+
raise TypeError('Unsupported type %s' % (type(o),))
13+
packed = packb(T(1, 42), strict_types=True, use_bin_type=True, default=default)
14+
unpacked = unpackb(packed, encoding='utf-8')
15+
assert unpacked == {'foo': 1, 'bar': 42}

0 commit comments

Comments
 (0)