msgpack-python/test/test_buffer.py

30 lines
730 B
Python
Raw Normal View History

#!/usr/bin/env python
from msgpack import packb, unpackb
2012-12-29 11:24:25 +09:00
def test_unpack_buffer():
from array import array
2019-12-05 18:51:45 +09:00
buf = array("b")
buf.frombytes(packb((b"foo", b"bar")))
2012-09-24 02:12:55 +09:00
obj = unpackb(buf, use_list=1)
2019-12-05 18:51:45 +09:00
assert [b"foo", b"bar"] == obj
def test_unpack_bytearray():
buf = bytearray(packb((b"foo", b"bar")))
obj = unpackb(buf, use_list=1)
2019-12-05 18:51:45 +09:00
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)
2016-05-07 15:18:20 +02:00
def test_unpack_memoryview():
buf = bytearray(packb((b"foo", b"bar")))
2016-05-07 15:18:20 +02:00
view = memoryview(buf)
obj = unpackb(view, use_list=1)
2019-12-05 18:51:45 +09:00
assert [b"foo", b"bar"] == obj
2016-05-07 15:18:20 +02:00
expected_type = bytes
assert all(type(s) == expected_type for s in obj)