def test_read_from(): size = 128 src = memory.Backend(data=bytearray(b"x" * size)) dst = memory.ReaderFrom("r+", bytearray(b"y" * size)) buf = bytearray(32) dst.read_from(src, size, buf) assert src.tell() == size assert dst.tell() == size assert src.data() == dst.data()
def test_read_from_some(): src = memory.Backend(data=bytearray(b"x" * 128)) dst = memory.ReaderFrom("r+", data=bytearray(b"y" * 128)) buf = bytearray(32) src.seek(32) dst.seek(32) dst.read_from(src, 64, buf) assert src.tell() == 96 assert dst.tell() == 96 assert dst.data() == b"y" * 32 + b"x" * 64 + b"y" * 32
def test_copy_read_from(buffer_size, zero, hole, progress): src_extents = create_zero_extents("B0-") src_backing = create_backing("B0-") dst_backing = create_backing( "AAA" if zero and hole else "AA0" if zero else "A00") src = memory.Backend(mode="r", data=src_backing, extents={"zero": src_extents}) dst = memory.ReaderFrom("r+", data=dst_backing) io.copy(src, dst, max_workers=1, buffer_size=buffer_size, zero=zero, hole=hole, progress=progress) assert dst_backing == src_backing