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

Method test_list

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

Source from the content-addressed store, hash-verified

3495 tar.addfile(replaced, f)
3496
3497 def test_list(self):
3498 # Change some metadata to None, then compare list() output
3499 # word-for-word. We want list() to not raise, and to only change
3500 # printout for the affected piece of metadata.
3501 # (n.b.: some contents of the test archive are hardcoded.)
3502 for attr_names in ({'mtime'}, {'mode'}, {'uid'}, {'gid'},
3503 {'uname'}, {'gname'},
3504 {'uid', 'uname'}, {'gid', 'gname'}):
3505 with (self.subTest(attr_names=attr_names),
3506 tarfile.open(tarname, encoding="iso8859-1") as tar):
3507 tio_prev = io.TextIOWrapper(io.BytesIO(), 'ascii', newline='\n')
3508 with support.swap_attr(sys, 'stdout', tio_prev):
3509 tar.list()
3510 for member in tar.getmembers():
3511 for attr_name in attr_names:
3512 setattr(member, attr_name, None)
3513 tio_new = io.TextIOWrapper(io.BytesIO(), 'ascii', newline='\n')
3514 with support.swap_attr(sys, 'stdout', tio_new):
3515 tar.list()
3516 for expected, got in zip(tio_prev.detach().getvalue().split(),
3517 tio_new.detach().getvalue().split()):
3518 if attr_names == {'mtime'} and re.match(rb'2003-01-\d\d', expected):
3519 self.assertEqual(got, b'????-??-??')
3520 elif attr_names == {'mtime'} and re.match(rb'\d\d:\d\d:\d\d', expected):
3521 self.assertEqual(got, b'??:??:??')
3522 elif attr_names == {'mode'} and re.match(
3523 rb'.([r-][w-][x-]){3}', expected):
3524 self.assertEqual(got, b'??????????')
3525 elif attr_names == {'uname'} and expected.startswith(
3526 (b'tarfile/', b'lars/', b'foo/')):
3527 exp_user, exp_group = expected.split(b'/')
3528 got_user, got_group = got.split(b'/')
3529 self.assertEqual(got_group, exp_group)
3530 self.assertRegex(got_user, b'[0-9]+')
3531 elif attr_names == {'gname'} and expected.endswith(
3532 (b'/tarfile', b'/users', b'/bar')):
3533 exp_user, exp_group = expected.split(b'/')
3534 got_user, got_group = got.split(b'/')
3535 self.assertEqual(got_user, exp_user)
3536 self.assertRegex(got_group, b'[0-9]+')
3537 elif attr_names == {'uid'} and expected.startswith(
3538 (b'1000/')):
3539 exp_user, exp_group = expected.split(b'/')
3540 got_user, got_group = got.split(b'/')
3541 self.assertEqual(got_group, exp_group)
3542 self.assertEqual(got_user, b'None')
3543 elif attr_names == {'gid'} and expected.endswith((b'/100')):
3544 exp_user, exp_group = expected.split(b'/')
3545 got_user, got_group = got.split(b'/')
3546 self.assertEqual(got_user, exp_user)
3547 self.assertEqual(got_group, b'None')
3548 elif attr_names == {'uid', 'uname'} and expected.startswith(
3549 (b'tarfile/', b'lars/', b'foo/', b'1000/')):
3550 exp_user, exp_group = expected.split(b'/')
3551 got_user, got_group = got.split(b'/')
3552 self.assertEqual(got_group, exp_group)
3553 self.assertEqual(got_user, b'None')
3554 elif attr_names == {'gname', 'gid'} and expected.endswith(

Callers

nothing calls this directly

Calls 12

detachMethod · 0.95
getmembersMethod · 0.80
assertRegexMethod · 0.80
subTestMethod · 0.45
openMethod · 0.45
listMethod · 0.45
splitMethod · 0.45
getvalueMethod · 0.45
matchMethod · 0.45
assertEqualMethod · 0.45
startswithMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected