Пример #1
0
def test_fixed_size_file_object():
    arr = [str(i).encode() * 20 for i in range(10)]
    bts = os.linesep.encode().join(arr)
    bio = BytesIO(bts)

    ref_bio = BytesIO(bio.read(100))
    bio.seek(0)
    ref_bio.seek(0)
    fix_bio = utils.FixedSizeFileObject(bio, 100)

    assert ref_bio.readline() == fix_bio.readline()
    assert ref_bio.tell() == fix_bio.tell()
    pos = ref_bio.tell() + 10
    assert ref_bio.seek(pos) == fix_bio.seek(pos)
    assert ref_bio.read(5) == fix_bio.read(5)
    assert ref_bio.readlines(25) == fix_bio.readlines(25)
    assert list(ref_bio) == list(fix_bio)
Пример #2
0
    def testFixedSizeFileObject(self):
        arr = [str(i).encode() * 20 for i in range(10)]
        bts = os.linesep.encode().join(arr)
        bio = BytesIO(bts)

        ref_bio = BytesIO(bio.read(100))
        bio.seek(0)
        ref_bio.seek(0)
        fix_bio = utils.FixedSizeFileObject(bio, 100)

        self.assertEqual(ref_bio.readline(), fix_bio.readline())
        self.assertEqual(ref_bio.tell(), fix_bio.tell())
        pos = ref_bio.tell() + 10
        self.assertEqual(ref_bio.seek(pos), fix_bio.seek(pos))
        self.assertEqual(ref_bio.read(5), fix_bio.read(5))
        self.assertEqual(ref_bio.readlines(25), fix_bio.readlines(25))
        self.assertEqual(list(ref_bio), list(fix_bio))