diff options
author | Joel Nothman <joel.nothman@gmail.com> | 2012-09-23 11:13:44 +1000 |
---|---|---|
committer | Joel Nothman <joel.nothman@gmail.com> | 2012-09-23 20:46:49 +1000 |
commit | e7c51d9089e9270ce197c00a6af1c60e45f36e97 (patch) | |
tree | 8d5c683b5406bcdf7abc37d1a6e866e1413a7435 /test | |
parent | ffec10dff3839ae182cff3d9fff67ab3fe6165be (diff) | |
download | msgpack-python-e7c51d9089e9270ce197c00a6af1c60e45f36e97.tar.gz |
Cleaner read_bytes and a test case
No longer reads via buffer for unbuffered bytes
Diffstat (limited to 'test')
-rw-r--r-- | test/test_sequnpack.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/test_sequnpack.py b/test/test_sequnpack.py index b1b80b2..c763f40 100644 --- a/test/test_sequnpack.py +++ b/test/test_sequnpack.py @@ -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() |