diff options
author | Cody Maloney <cmaloney@users.noreply.github.com> | 2024-07-24 06:14:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-24 06:14:35 (GMT) |
commit | 9eb734111be90399fb6ae2f717d736abb8e518cb (patch) | |
tree | b1670b5a2a4f4cd8e16358fd4d2434d062a90df6 /Lib | |
parent | e91ef13861e88c27aed51a24e58d1dcc855a01dc (diff) | |
download | cpython-9eb734111be90399fb6ae2f717d736abb8e518cb.zip cpython-9eb734111be90399fb6ae2f717d736abb8e518cb.tar.gz cpython-9eb734111be90399fb6ae2f717d736abb8e518cb.tar.bz2 |
GH-120754: Add more tests around seek + readall (#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/121593#issuecomment-2222261986
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_largefile.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py index 849b6cb..41f7b70 100644 --- a/Lib/test/test_largefile.py +++ b/Lib/test/test_largefile.py @@ -141,6 +141,9 @@ class TestFileMethods(LargeFileTest): 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): @@ -151,6 +154,22 @@ class TestFileMethods(LargeFileTest): 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): |