diff options
author | jfolz <theriddling@gmail.com> | 2020-06-08 05:14:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-08 12:14:50 +0900 |
commit | c1b1a23f62d5e0ec39a1910d2e9580ce1c13a1cf (patch) | |
tree | 9726bba0edf80ba9515495c315d7966f7b7aa37e /test | |
parent | b04690012d5d77cfe5074893686c4d55ec780300 (diff) | |
download | msgpack-python-c1b1a23f62d5e0ec39a1910d2e9580ce1c13a1cf.tar.gz |
Fix Unpacker.tell() (#427)
Fixes #426.
Co-authored-by: folz <joachim.folz@dfki.de>
Diffstat (limited to 'test')
-rw-r--r-- | test/test_unpack.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/test_unpack.py b/test/test_unpack.py index bc74c4d..057b7bf 100644 --- a/test/test_unpack.py +++ b/test/test_unpack.py @@ -3,6 +3,11 @@ import sys from msgpack import Unpacker, packb, OutOfData, ExtType from pytest import raises, mark +try: + from itertools import izip as zip +except ImportError: + pass + def test_unpack_array_header_from_file(): f = BytesIO(packb([1, 2, 3, 4])) @@ -64,7 +69,31 @@ def test_unpacker_ext_hook(): assert unpacker.unpack() == {"a": ExtType(2, b"321")} +def test_unpacker_tell(): + objects = 1, 2, u"abc", u"def", u"ghi" + packed = b"\x01\x02\xa3abc\xa3def\xa3ghi" + positions = 1, 2, 6, 10, 14 + unpacker = Unpacker(BytesIO(packed)) + for obj, unp, pos in zip(objects, unpacker, positions): + assert obj == unp + assert pos == unpacker.tell() + + +def test_unpacker_tell_read_bytes(): + objects = 1, u"abc", u"ghi" + packed = b"\x01\x02\xa3abc\xa3def\xa3ghi" + raw_data = b"\x02", b"\xa3def", b"" + lenghts = 1, 4, 999 + positions = 1, 6, 14 + unpacker = Unpacker(BytesIO(packed)) + for obj, unp, pos, n, raw in zip(objects, unpacker, positions, lenghts, raw_data): + assert obj == unp + assert pos == unpacker.tell() + assert unpacker.read_bytes(n) == raw + + if __name__ == "__main__": test_unpack_array_header_from_file() test_unpacker_hook_refcnt() test_unpacker_ext_hook() + test_unpacker_tell() |