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

Method test_list

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected