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
def test_unpack_tell(): stream = io.BytesIO() messages = [2**i-1 for i in range(65)] messages += [-(2**i) for i in range(1, 64)] messages += [b'hello', b'hello'*1000, list(range(20)), {i: bytes(i)*i for i in range(10)}, {i: bytes(i)*i for i in range(32)}] offsets = [] for m in messages: pack(m, stream) offsets.append(stream.tell()) stream.seek(0) unpacker = Unpacker(stream) for m, o in zip(messages, offsets): m2 = next(unpacker) assert m == m2 assert o == unpacker.tell()
def test_unpack_tell(): stream = io.BytesIO() messages = [2**i - 1 for i in range(65)] messages += [-(2**i) for i in range(1, 64)] messages += [ b'hello', b'hello' * 1000, list(range(20)), {i: bytes(i) * i for i in range(10)}, {i: bytes(i) * i for i in range(32)} ] offsets = [] for m in messages: pack(m, stream) offsets.append(stream.tell()) stream.seek(0) unpacker = Unpacker(stream) for m, o in zip(messages, offsets): m2 = next(unpacker) assert m == m2 assert o == unpacker.tell()