Skip to content

Commit 9dad694

Browse files
[3.12] GH-120754: Add more tests around seek + readall (GH-122103) (#122216)
GH-120754: Add more tests around seek + readall (GH-122103) In the process of speeding up readall, A number of related tests (ex. large file tests in test_zipfile) found problems with the change I was making. This adds I/O tests to specifically test these cases to help ensure they don't regress and hopefully make debugging easier. This is part of the improvements from https://github.com/python/cpython/pull/121593GH-issuecomment-2222261986 (cherry picked from commit 9eb7341) Co-authored-by: Cody Maloney <[email protected]>
1 parent 257c413 commit 9dad694

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Lib/test/test_largefile.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ def test_truncate(self):
142142
f.truncate(1)
143143
self.assertEqual(f.tell(), 0) # else pointer moved
144144
f.seek(0)
145+
# Verify readall on a truncated file is well behaved. read()
146+
# without a size can be unbounded, this should get just the byte
147+
# that remains.
145148
self.assertEqual(len(f.read()), 1) # else wasn't truncated
146149

147150
def test_seekable(self):
@@ -152,6 +155,22 @@ def test_seekable(self):
152155
f.seek(pos)
153156
self.assertTrue(f.seekable())
154157

158+
@bigmemtest(size=size, memuse=2, dry_run=False)
159+
def test_seek_readall(self, _size):
160+
# Seek which doesn't change position should readall successfully.
161+
with self.open(TESTFN, 'rb') as f:
162+
self.assertEqual(f.seek(0, os.SEEK_CUR), 0)
163+
self.assertEqual(len(f.read()), size + 1)
164+
165+
# Seek which changes (or might change) position should readall
166+
# successfully.
167+
with self.open(TESTFN, 'rb') as f:
168+
self.assertEqual(f.seek(20, os.SEEK_SET), 20)
169+
self.assertEqual(len(f.read()), size - 19)
170+
171+
with self.open(TESTFN, 'rb') as f:
172+
self.assertEqual(f.seek(-3, os.SEEK_END), size - 2)
173+
self.assertEqual(len(f.read()), 3)
155174

156175
def skip_no_disk_space(path, required):
157176
def decorator(fun):

0 commit comments

Comments
 (0)