Skip to content

Commit

Permalink
pythonGH-120754: Add more tests around seek + readall
Browse files Browse the repository at this point in the history
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
python#121593 (comment)
  • Loading branch information
cmaloney committed Jul 21, 2024
1 parent 5901d92 commit 0c48c43
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Lib/test/test_largefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ def test_truncate(self):
f.truncate(1)
self.assertEqual(f.tell(), 0) # else pointer moved
f.seek(0)
# Verify readall on a truncated file is well behaved. read()
# without a size can be unbounded, this should get just the byte
# that remains.
self.assertEqual(len(f.read()), 1) # else wasn't truncated

def test_seekable(self):
Expand All @@ -151,6 +154,22 @@ def test_seekable(self):
f.seek(pos)
self.assertTrue(f.seekable())

@bigmemtest(size=size, memuse=2, dry_run=False)
def test_seek_readall(self, _size):
# Seek which doesn't change position should readall successfully.
with self.open(TESTFN, 'rb') as f:
self.assertEqual(f.seek(0, os.SEEK_CUR), 0)
self.assertEqual(len(f.read()), size+1)

# Seek which changes (or might change) position should readall
# successfully.
with self.open(TESTFN, 'rb') as f:
self.assertEqual(f.seek(20, os.SEEK_SET), 20)
self.assertEqual(len(f.read()), size-19)

with self.open(TESTFN, 'rb') as f:
self.assertEqual(f.seek(-3, os.SEEK_END), size - 2)
self.assertEqual(len(f.read()), 3)

def skip_no_disk_space(path, required):
def decorator(fun):
Expand Down

0 comments on commit 0c48c43

Please sign in to comment.