def test_horcurx__read_message_bytes_small(hx): hx._write_bytes(b'123') hx._write_bytes(b'4567890') stream = hx.stream del hx stream.seek(0) hx = hio.Horcrux(stream) m1 = hx._read_message_bytes() assert m1 == b'123' m2 = hx._read_message_bytes() assert m2 == b'4567890'
def test_horcrux_init_read(share): stream = io.BytesIO( b'\x1b\n\x100123456789abcdef\x10\x02\x1a' b'\x05\x12\x03123\x18\n\nu\x14Op\xa3\x13\x01Jt\xa8\x1a\nslkfjwnfa;') stream.seek(0) hx = hio.Horcrux(stream) hx.init_read() assert hx.share == share assert hx.hrcx_id == 0 assert hx.encrypted_filename == b'slkfjwnfa;' assert hx.next_block_id == None
def test_horcrux_write_stream_header(hx): header = b'u\x14Op\xa3\x13\x01Jt\xa8' hx._write_stream_header(header) hx._write_stream_header(header, encrypted_filename=b'testname') stream = hx.stream del hx stream.seek(0) hx = hio.Horcrux(stream) h1 = hx._read_message_bytes() assert h1 == b'\n\nu\x14Op\xa3\x13\x01Jt\xa8' h2 = hx._read_message_bytes() assert h2 == b'\n\nu\x14Op\xa3\x13\x01Jt\xa8\x1a\x08testname'
def test_horcrux__read_message_bytes_large(hx): m1 = bytes(255 for _ in range(500)) m2 = bytes(random.getrandbits(8) for _ in range(4)) m3 = bytes(random.getrandbits(8) for _ in range(4096)) for m in (m1, m2, m3): hx._write_bytes(m) stream = hx.stream del hx stream.seek(0) hx = hio.Horcrux(stream) assert hx._read_message_bytes() == m1 assert hx._read_message_bytes() == m2 assert hx._read_message_bytes() == m3
def test_horcrux_skip_block(hx): data1 = bytes(255 for _ in range(30)) data2 = bytes(255 for _ in range(30)) hx.write_data_block(33, data1) hx.write_data_block(45, data2) stream = hx.stream stream.seek(0) del hx hx = hio.Horcrux(stream) hx._read_next_block_id() hx.skip_block() _id, d = hx.read_block() assert d == data2 assert _id == 45
def test_init_horcrux(): h = hio.Horcrux(io.BytesIO())
def hx(): return hio.Horcrux(io.BytesIO())