def test_bufview_readinto(buftype): buf = buftype(30) buf[:] = b"a" * 30 r = io.BytesIO(b"b" * 20) view = compat.bufview(buf, 10, 10) r.readinto(view) assert buf[:] == b"a" * 10 + b"b" * 10 + b"a" * 10
def test_bufview_write(buftype): buf = buftype(30) buf[:] = b"a" * 10 + b"b" * 10 + b"c" * 10 view = compat.bufview(buf, 10, 10) w = io.BytesIO() w.write(view) assert w.getvalue() == b"b" * 10
def test_bufview_readwrite(buftype): buf = buftype(30) buf[:] = b"a" * 30 view = compat.bufview(buf, 10, 10) view[:] = b"b" * 10 assert buf[:] == b"a" * 10 + b"b" * 10 + b"a" * 10
def test_bufview_readonly(buftype): buf = buftype(30) buf[:] = b"a" * 10 + b"b" * 10 + b"c" * 10 view = compat.bufview(buf, 10, 10) assert view[:] == b"b" * 10