mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-11-10 22:41:03 +00:00
Add test for strict_types option
This commit is contained in:
parent
628c519187
commit
a779b79b47
1 changed files with 15 additions and 0 deletions
15
test/test_stricttype.py
Normal file
15
test/test_stricttype.py
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
from msgpack import packb, unpackb
|
||||||
|
|
||||||
|
|
||||||
|
def test_namedtuple():
|
||||||
|
T = namedtuple('T', "foo bar")
|
||||||
|
def default(o):
|
||||||
|
if isinstance(o, T):
|
||||||
|
return dict(o._asdict())
|
||||||
|
raise TypeError('Unsupported type %s' % (type(o),))
|
||||||
|
packed = packb(T(1, 42), strict_types=True, use_bin_type=True, default=default)
|
||||||
|
unpacked = unpackb(packed, encoding='utf-8')
|
||||||
|
assert unpacked == {'foo': 1, 'bar': 42}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue