def test_FileView_multiple_reads(): from oniontree.fileview import FileView basefile = BytesIO(os.urandom(1024)) fv = FileView(basefile, 512, 512) basefile.seek(512) for i in range(0, 512, 4): assert basefile.read(4) == fv.read(4) assert basefile.read(10) == fv.read(10)
def test_FileView_multiple_reads_with_seeks(): from oniontree.fileview import FileView import random basefile = BytesIO(os.urandom(1024)) fv = FileView(basefile, 512, 512) basefile.seek(512) offsets = list(range(0, 512, 4)) random.shuffle(offsets) for i in offsets: fv.seek(i) basefile.seek(i+512) assert basefile.read(4) == fv.read(4)