diff options
author | Bénédikt Tran <10796600+picnixz@users.noreply.github.com> | 2024-11-24 16:36:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-24 16:36:15 (GMT) |
commit | e0ef08f5b444950ad9e900b27f5b5dbc706f4459 (patch) | |
tree | 00a5c9b4c3905591f7a0b43c0264a69ed5c8c57d /Lib/test | |
parent | 3d8ac48aed6e27c43bf5d037018edcc31d9e66d8 (diff) | |
download | cpython-e0ef08f5b444950ad9e900b27f5b5dbc706f4459.zip cpython-e0ef08f5b444950ad9e900b27f5b5dbc706f4459.tar.gz cpython-e0ef08f5b444950ad9e900b27f5b5dbc706f4459.tar.bz2 |
gh-122356: restore the position of a file-like object after `zipfile.is_zipfile` (#122397)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_zipfile/test_core.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/test/test_zipfile/test_core.py b/Lib/test/test_zipfile/test_core.py index 36f7f54..c36228c 100644 --- a/Lib/test/test_zipfile/test_core.py +++ b/Lib/test/test_zipfile/test_core.py @@ -1969,10 +1969,16 @@ class OtherTests(unittest.TestCase): zip_contents = fp.read() # - passing a file-like object fp = io.BytesIO() - fp.write(zip_contents) + end = fp.write(zip_contents) + self.assertEqual(fp.tell(), end) + mid = end // 2 + fp.seek(mid, 0) self.assertTrue(zipfile.is_zipfile(fp)) - fp.seek(0, 0) + # check that the position is left unchanged after the call + # see: https://github.com/python/cpython/issues/122356 + self.assertEqual(fp.tell(), mid) self.assertTrue(zipfile.is_zipfile(fp)) + self.assertEqual(fp.tell(), mid) def test_non_existent_file_raises_OSError(self): # make sure we don't raise an AttributeError when a partially-constructed |