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

Method test_add

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

Source from the content-addressed store, hash-verified

3450
3451class NoneInfoTests_Misc(unittest.TestCase):
3452 def test_add(self):
3453 # When addfile() encounters None metadata, it raises a ValueError
3454 bio = io.BytesIO()
3455 for tarformat in (tarfile.USTAR_FORMAT, tarfile.GNU_FORMAT,
3456 tarfile.PAX_FORMAT):
3457 with self.subTest(tarformat=tarformat):
3458 tar = tarfile.open(fileobj=bio, mode='w', format=tarformat)
3459 tarinfo = tar.gettarinfo(tarname)
3460 try:
3461 with open(tarname, 'rb') as f:
3462 tar.addfile(tarinfo, f)
3463 except Exception:
3464 if tarformat == tarfile.USTAR_FORMAT:
3465 # In the old, limited format, adding might fail for
3466 # reasons like the UID being too large
3467 pass
3468 else:
3469 raise
3470 else:
3471 for attr_name in ('mtime', 'mode', 'uid', 'gid',
3472 'uname', 'gname'):
3473 with self.subTest(attr_name=attr_name):
3474 replaced = tarinfo.replace(**{attr_name: None})
3475 with self.assertRaisesRegex(ValueError,
3476 f"{attr_name}"):
3477 with open(tarname, 'rb') as f:
3478 tar.addfile(replaced, f)
3479
3480 def test_list(self):
3481 # Change some metadata to None, then compare list() output

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected