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

Method test_fileobj_seek

Lib/test/test_tarfile.py:165–212  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

163 "fileobj.__iter__() failed")
164
165 def test_fileobj_seek(self):
166 self.tar.extract("ustar/regtype", TEMPDIR,
167 filter='data')
168 with open(os.path.join(TEMPDIR, "ustar/regtype"), "rb") as fobj:
169 data = fobj.read()
170
171 tarinfo = self.tar.getmember("ustar/regtype")
172 with self.tar.extractfile(tarinfo) as fobj:
173 text = fobj.read()
174 fobj.seek(0)
175 self.assertEqual(0, fobj.tell(),
176 "seek() to file's start failed")
177 fobj.seek(2048, 0)
178 self.assertEqual(2048, fobj.tell(),
179 "seek() to absolute position failed")
180 fobj.seek(-1024, 1)
181 self.assertEqual(1024, fobj.tell(),
182 "seek() to negative relative position failed")
183 fobj.seek(1024, 1)
184 self.assertEqual(2048, fobj.tell(),
185 "seek() to positive relative position failed")
186 s = fobj.read(10)
187 self.assertEqual(s, data[2048:2058],
188 "read() after seek failed")
189 fobj.seek(0, 2)
190 self.assertEqual(tarinfo.size, fobj.tell(),
191 "seek() to file's end failed")
192 self.assertEqual(fobj.read(), b"",
193 "read() at file's end did not return empty string")
194 fobj.seek(-tarinfo.size, 2)
195 self.assertEqual(0, fobj.tell(),
196 "relative seek() to file's end failed")
197 fobj.seek(512)
198 s1 = fobj.readlines()
199 fobj.seek(512)
200 s2 = fobj.readlines()
201 self.assertEqual(s1, s2,
202 "readlines() after seek failed")
203 fobj.seek(0)
204 self.assertEqual(len(fobj.readline()), fobj.tell(),
205 "tell() after readline() failed")
206 fobj.seek(512)
207 self.assertEqual(len(fobj.readline()) + 512, fobj.tell(),
208 "tell() after seek() and readline() failed")
209 fobj.seek(0)
210 line = fobj.readline()
211 self.assertEqual(fobj.read(), data[len(line):],
212 "read() after readline() failed")
213
214 def test_fileobj_text(self):
215 with self.tar.extractfile("ustar/regtype") as fobj:

Callers

nothing calls this directly

Calls 11

getmemberMethod · 0.80
extractfileMethod · 0.80
openFunction · 0.50
extractMethod · 0.45
joinMethod · 0.45
readMethod · 0.45
seekMethod · 0.45
assertEqualMethod · 0.45
tellMethod · 0.45
readlinesMethod · 0.45
readlineMethod · 0.45

Tested by

no test coverage detected