MCPcopy Index your code
hub / github.com/python/cpython / test_seek_tell

Method test_seek_tell

Lib/test/test_zipfile/test_core.py:2894–2929  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2892 self.zip.open("test.txt")
2893
2894 def test_seek_tell(self):
2895 self.zip.setpassword(b"python")
2896 txt = self.plain
2897 test_word = b'encryption'
2898 bloc = txt.find(test_word)
2899 bloc_len = len(test_word)
2900 with self.zip.open("test.txt", "r") as fp:
2901 fp.seek(bloc, os.SEEK_SET)
2902 self.assertEqual(fp.tell(), bloc)
2903 fp.seek(-bloc, os.SEEK_CUR)
2904 self.assertEqual(fp.tell(), 0)
2905 fp.seek(bloc, os.SEEK_CUR)
2906 self.assertEqual(fp.tell(), bloc)
2907 self.assertEqual(fp.read(bloc_len), txt[bloc:bloc+bloc_len])
2908
2909 # Make sure that the second read after seeking back beyond
2910 # _readbuffer returns the same content (ie. rewind to the start of
2911 # the file to read forward to the required position).
2912 old_read_size = fp.MIN_READ_SIZE
2913 fp.MIN_READ_SIZE = 1
2914 fp._readbuffer = b''
2915 fp._offset = 0
2916 fp.seek(0, os.SEEK_SET)
2917 self.assertEqual(fp.tell(), 0)
2918 fp.seek(bloc, os.SEEK_CUR)
2919 self.assertEqual(fp.read(bloc_len), txt[bloc:bloc+bloc_len])
2920 fp.MIN_READ_SIZE = old_read_size
2921
2922 fp.seek(0, os.SEEK_END)
2923 self.assertEqual(fp.tell(), len(txt))
2924 fp.seek(0, os.SEEK_SET)
2925 self.assertEqual(fp.tell(), 0)
2926
2927 # Read the file completely to definitely call any eof integrity
2928 # checks (crc) and make sure they still pass.
2929 fp.read()
2930
2931
2932class AbstractTestsWithRandomBinaryFiles:

Callers

nothing calls this directly

Calls 7

setpasswordMethod · 0.80
findMethod · 0.45
openMethod · 0.45
seekMethod · 0.45
assertEqualMethod · 0.45
tellMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected