2010-11-02 14:09:50 +09:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
from msgpack import packb, unpackb
|
2014-02-12 23:09:23 +04:00
|
|
|
import sys
|
2010-11-02 14:09:50 +09:00
|
|
|
|
2012-12-29 11:24:25 +09:00
|
|
|
|
2010-11-02 14:09:50 +09:00
|
|
|
def test_unpack_buffer():
|
|
|
|
from array import array
|
2012-06-19 13:55:14 +09:00
|
|
|
buf = array('b')
|
2010-11-03 03:11:00 +09:00
|
|
|
buf.fromstring(packb(('foo', 'bar')))
|
2012-09-24 02:12:55 +09:00
|
|
|
obj = unpackb(buf, use_list=1)
|
2012-12-29 11:24:25 +09:00
|
|
|
assert [b'foo', b'bar'] == obj
|
2010-11-02 14:09:50 +09:00
|
|
|
|
2013-12-15 16:22:39 +00:00
|
|
|
|
|
|
|
def test_unpack_bytearray():
|
|
|
|
buf = bytearray(packb(('foo', 'bar')))
|
|
|
|
obj = unpackb(buf, use_list=1)
|
|
|
|
assert [b'foo', b'bar'] == obj
|
2014-02-12 23:09:23 +04:00
|
|
|
expected_type = bytes if sys.version_info[0] == 3 else str
|
|
|
|
assert all(type(s)==expected_type for s in obj)
|
|
|
|
|
2013-12-15 16:22:39 +00:00
|
|
|
|