def test_reads_only_from_start_to_end(self, data, testfile): with testfile.open() as f: assert Subfile(f, 2, 6).read() == data[2:6] with testfile.open() as f: assert Subfile(f, 2, 6).read(8) == data[2:6] with testfile.open() as f: assert Subfile(f, 2, 6).readline() == data[2:6] with testfile.open() as f: assert Subfile(f, 2, 6).readline(8) == data[2:6]
def test_seek_after_end(self, testfile): with testfile.open() as f: sf = Subfile(f, 2, 6) sf.seek(8) assert sf.read() == "" with testfile.open() as f: sf = Subfile(f, 2, 6) sf.read(1) sf.seek(8, os.SEEK_CUR) assert sf.read() == "" with testfile.open() as f: sf = Subfile(f, 2, 6) sf.seek(8, os.SEEK_END) assert sf.read() == ""
def test_seek_before_start(self, data, testfile): with testfile.open() as f: sf = Subfile(f, 2, 6) sf.seek(-2) assert sf.read() == data[2:6] with testfile.open() as f: sf = Subfile(f, 2, 6) sf.read(1) sf.seek(-4, os.SEEK_CUR) assert sf.read() == data[2:6] with testfile.open() as f: sf = Subfile(f, 2, 6) sf.seek(-8, os.SEEK_END) assert sf.read() == data[2:6]
def test_seek(self, data, testfile): with testfile.open() as f: sf = Subfile(f, 2, 6) sf.seek(2) assert sf.read() == data[4:6] with testfile.open() as f: sf = Subfile(f, 2, 6) sf.read(1) sf.seek(2, os.SEEK_CUR) assert sf.read() == data[5:6] with testfile.open() as f: sf = Subfile(f, 2, 6) sf.seek(-2, os.SEEK_END) assert sf.read() == data[4:6]
def test_readinto(self, data, testfile): b = bytearray(4) with testfile.open("rb") as f: assert Subfile(f, 2, 6).readinto(b) == 4 assert b == b"2345"
def test_readline(self, data, testfile): with testfile.open() as f: assert Subfile(f, 2, 14).readline() == data[2:11] with testfile.open() as f: assert Subfile(f, 2, 14).readline(15) == data[2:11]
def test_respects_read_size(self, data, testfile): with testfile.open() as f: assert Subfile(f, 2, 6).read(2) == data[2:4] with testfile.open() as f: assert Subfile(f, 2, 6).readline(2) == data[2:4]
def test_tell(self, data, testfile): with testfile.open() as f: sf = Subfile(f, 2, 6) assert sf.tell() == 0 sf.seek(3) assert sf.tell() == 3
def test_seek_after_end(self, testfile): with testfile.open() as f: sf = Subfile(f, 2, 6) sf.seek(8) assert sf.read() == '' with testfile.open() as f: sf = Subfile(f, 2, 6) sf.read(1) sf.seek(8, os.SEEK_CUR) assert sf.read() == '' with testfile.open() as f: sf = Subfile(f, 2, 6) sf.seek(8, os.SEEK_END) assert sf.read() == ''