Cleaner read_bytes and a test case

No longer reads via buffer for unbuffered bytes
This commit is contained in:
Joel Nothman 2012-09-23 11:13:44 +10:00
parent ffec10dff3
commit e7c51d9089
2 changed files with 21 additions and 7 deletions

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python
# coding: utf-8
import six
from msgpack import Unpacker, BufferFull
import nose
@ -42,5 +43,20 @@ def test_maxbuffersize():
assert ord('b') == next(unpacker)
def test_readbytes():
unpacker = Unpacker(read_size=3)
unpacker.feed(b'foobar')
assert unpacker.unpack() == ord(b'f')
assert unpacker.read_bytes(3) == b'oob'
assert unpacker.unpack() == ord(b'a')
assert unpacker.unpack() == ord(b'r')
# Test buffer refill
unpacker = Unpacker(six.BytesIO(b'foobar'), read_size=3)
assert unpacker.unpack() == ord(b'f')
assert unpacker.read_bytes(3) == b'oob'
assert unpacker.unpack() == ord(b'a')
assert unpacker.unpack() == ord(b'r')
if __name__ == '__main__':
nose.main()