msgpack-python/test/test_buffer.py

21 lines
489 B
Python
Raw Normal View History

#!/usr/bin/env python
# coding: utf-8
from msgpack import packb, unpackb
2012-12-29 11:24:25 +09:00
def test_unpack_buffer():
from array import array
2012-06-19 13:55:14 +09:00
buf = array('b')
2014-02-17 04:06:58 +09:00
buf.fromstring(packb((b'foo', b'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
def test_unpack_bytearray():
buf = bytearray(packb(('foo', 'bar')))
obj = unpackb(buf, use_list=1)
assert [b'foo', b'bar'] == obj
2014-02-17 04:06:58 +09:00
expected_type = bytes
assert all(type(s) == expected_type for s in obj)