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

Method test_ignore_zeros

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

Source from the content-addressed store, hash-verified

471 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname)
472
473 def test_ignore_zeros(self):
474 # Test TarFile's ignore_zeros option.
475 # generate 512 pseudorandom bytes
476 data = Random(0).randbytes(512)
477 for char in (b'\0', b'a'):
478 # Test if EOFHeaderError ('\0') and InvalidHeaderError ('a')
479 # are ignored correctly.
480 with self.open(tmpname, "w") as fobj:
481 fobj.write(char * 1024)
482 tarinfo = tarfile.TarInfo("foo")
483 tarinfo.size = len(data)
484 fobj.write(tarinfo.tobuf())
485 fobj.write(data)
486
487 tar = tarfile.open(tmpname, mode="r", ignore_zeros=True)
488 try:
489 self.assertListEqual(tar.getnames(), ["foo"],
490 "ignore_zeros=True should have skipped the %r-blocks" %
491 char)
492 finally:
493 tar.close()
494
495 def test_premature_end_of_archive(self):
496 for size in (512, 600, 1024, 1200):

Callers

nothing calls this directly

Calls 8

tobufMethod · 0.95
RandomClass · 0.90
assertListEqualMethod · 0.80
getnamesMethod · 0.80
randbytesMethod · 0.45
openMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected