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

Method test_add

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

Source from the content-addressed store, hash-verified

3467
3468class NoneInfoTests_Misc(unittest.TestCase):
3469 def test_add(self):
3470 # When addfile() encounters None metadata, it raises a ValueError
3471 bio = io.BytesIO()
3472 for tarformat in (tarfile.USTAR_FORMAT, tarfile.GNU_FORMAT,
3473 tarfile.PAX_FORMAT):
3474 with self.subTest(tarformat=tarformat):
3475 tar = tarfile.open(fileobj=bio, mode='w', format=tarformat)
3476 tarinfo = tar.gettarinfo(tarname)
3477 try:
3478 with open(tarname, 'rb') as f:
3479 tar.addfile(tarinfo, f)
3480 except Exception:
3481 if tarformat == tarfile.USTAR_FORMAT:
3482 # In the old, limited format, adding might fail for
3483 # reasons like the UID being too large
3484 pass
3485 else:
3486 raise
3487 else:
3488 for attr_name in ('mtime', 'mode', 'uid', 'gid',
3489 'uname', 'gname'):
3490 with self.subTest(attr_name=attr_name):
3491 replaced = tarinfo.replace(**{attr_name: None})
3492 with self.assertRaisesRegex(ValueError,
3493 f"{attr_name}"):
3494 with open(tarname, 'rb') as f:
3495 tar.addfile(replaced, f)
3496
3497 def test_list(self):
3498 # Change some metadata to None, then compare list() output

Callers

nothing calls this directly

Calls 7

gettarinfoMethod · 0.80
addfileMethod · 0.80
assertRaisesRegexMethod · 0.80
openFunction · 0.50
subTestMethod · 0.45
openMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected