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
result = False
try:
if hasattr(filename, "read"):
+ pos = filename.tell()
result = _check_zipfile(fp=filename)
+ filename.seek(pos)
else:
with open(filename, "rb") as fp:
result = _check_zipfile(fp)