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

Method test_ignore_zeros

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected