diff options
| author | INADA Naoki <methane@users.noreply.github.com> | 2016-01-25 11:37:07 +0900 |
|---|---|---|
| committer | INADA Naoki <methane@users.noreply.github.com> | 2016-01-25 11:37:07 +0900 |
| commit | 8036cb4e0e8e971c4396b5a8162aeff5b3459aa5 (patch) | |
| tree | 21aa54dea335a5fd7ac531fc9b75623999b83723 /test | |
| parent | c8513898e222a91ad7f6520aa8a4a5a1711cdc65 (diff) | |
| parent | a779b79b47529f84cd71593f284788d939226d66 (diff) | |
| download | msgpack-python-8036cb4e0e8e971c4396b5a8162aeff5b3459aa5.tar.gz | |
Merge pull request #158 from methane/feature/strict-typecheck
Packer: check type strictly
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_stricttype.py | 15 |
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} |
