mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-20 05:49:06 +02:00
python: Port some tests from 2 to 3.
This commit is contained in:
16
python/test3/test_buffer.py
Normal file
16
python/test3/test_buffer.py
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from nose import main
|
||||
from nose.tools import *
|
||||
from msgpack import packb, unpackb
|
||||
|
||||
def test_unpack_buffer():
|
||||
from array import array
|
||||
buf = array('b')
|
||||
buf.fromstring(packb(('foo', 'bar')))
|
||||
obj = unpackb(buf)
|
||||
assert_equal((b'foo', b'bar'), obj)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@@ -26,6 +26,19 @@ def test_decode_hook():
|
||||
unpacked = unpacks(packed, object_hook=_decode_complex)
|
||||
eq_(unpacked[1], 1+2j)
|
||||
|
||||
@raises(TypeError)
|
||||
def test_bad_hook():
|
||||
packed = packs([3, 1+2j], default=lambda o: o)
|
||||
unpacked = unpacks(packed)
|
||||
|
||||
def _arr_to_str(arr):
|
||||
return ''.join(str(c) for c in arr)
|
||||
|
||||
def test_array_hook():
|
||||
packed = packs([1,2,3])
|
||||
unpacked = unpacks(packed, list_hook=_arr_to_str)
|
||||
eq_(unpacked, '123')
|
||||
|
||||
if __name__ == '__main__':
|
||||
#main()
|
||||
test_decode_hook()
|
||||
|
Reference in New Issue
Block a user