Skip to content

Commit ba3aa5a

Browse files
[3.13] GH-120754: Add more tests around seek + readall (GH-122103) (#122215)
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 40cdec6 commit ba3aa5a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Lib/test/test_largefile.py

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

146149
def test_seekable(self):
@@ -151,6 +154,22 @@ def test_seekable(self):
151154
f.seek(pos)
152155
self.assertTrue(f.seekable())
153156

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

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

0 commit comments

Comments
 (0)