summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2016-01-25 02:18:25 +0900
committerINADA Naoki <songofacandy@gmail.com>2016-01-25 10:19:49 +0900
commita779b79b47529f84cd71593f284788d939226d66 (patch)
tree6a040ccda8f4cfcd731e5c20a345a3f13dd7f9fc /test
parent628c5191873148a8372bae4ee99454ad13b7b492 (diff)
downloadmsgpack-python-a779b79b47529f84cd71593f284788d939226d66.tar.gz
Add test for strict_types option
Diffstat (limited to 'test')
-rw-r--r--test/test_stricttype.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/test_stricttype.py b/test/test_stricttype.py
new file mode 100644
index 0000000..a20b5eb
--- /dev/null
+++ b/test/test_stricttype.py
@@ -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}