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

Method test_fileobj_with_offset

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

Source from the content-addressed store, hash-verified

621 tar = self.taropen(tmpname, '')
622
623 def test_fileobj_with_offset(self):
624 # Skip the first member and store values from the second member
625 # of the testtar.
626 tar = tarfile.open(self.tarname, mode=self.mode)
627 try:
628 tar.next()
629 t = tar.next()
630 name = t.name
631 offset = t.offset
632 with tar.extractfile(t) as f:
633 data = f.read()
634 finally:
635 tar.close()
636
637 # Open the testtar and seek to the offset of the second member.
638 with self.open(self.tarname) as fobj:
639 fobj.seek(offset)
640
641 # Test if the tarfile starts with the second member.
642 with tar.open(self.tarname, mode="r:", fileobj=fobj) as tar:
643 t = tar.next()
644 self.assertEqual(t.name, name)
645 # Read to the end of fileobj and test if seeking back to the
646 # beginning works.
647 tar.getmembers()
648 self.assertEqual(tar.extractfile(t).read(), data,
649 "seek back did not work")
650
651 def test_fail_comp(self):
652 # For Gzip and Bz2 Tests: fail with a ReadError on an uncompressed file.

Callers

nothing calls this directly

Calls 8

extractfileMethod · 0.80
getmembersMethod · 0.80
openMethod · 0.45
nextMethod · 0.45
readMethod · 0.45
closeMethod · 0.45
seekMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected