MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_fileobj_with_offset

Method test_fileobj_with_offset

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

Source from the content-addressed store, hash-verified

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