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

Method test_realpath_unreadable_directory

Lib/test/test_posixpath.py:857–894  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

855 @skip_if_ABSTFN_contains_backslash
856 @os_helper.skip_unless_symlink
857 def test_realpath_unreadable_directory(self):
858 try:
859 os.mkdir(ABSTFN)
860 os.mkdir(ABSTFN + '/k')
861 os.chmod(ABSTFN, 0o000)
862 self.assertEqual(realpath(ABSTFN, strict=False), ABSTFN)
863 self.assertEqual(realpath(ABSTFN, strict=True), ABSTFN)
864 self.assertEqual(realpath(ABSTFN, strict=ALL_BUT_LAST), ABSTFN)
865 self.assertEqual(realpath(ABSTFN, strict=ALLOW_MISSING), ABSTFN)
866
867 try:
868 os.stat(ABSTFN)
869 except PermissionError:
870 pass
871 else:
872 self.skipTest('Cannot block permissions')
873
874 self.assertEqual(realpath(ABSTFN + '/k', strict=False),
875 ABSTFN + '/k')
876 self.assertRaises(PermissionError, realpath, ABSTFN + '/k',
877 strict=True)
878 self.assertRaises(PermissionError, realpath, ABSTFN + '/k',
879 strict=ALL_BUT_LAST)
880 self.assertRaises(PermissionError, realpath, ABSTFN + '/k',
881 strict=ALLOW_MISSING)
882
883 self.assertEqual(realpath(ABSTFN + '/missing', strict=False),
884 ABSTFN + '/missing')
885 self.assertRaises(PermissionError, realpath, ABSTFN + '/missing',
886 strict=True)
887 self.assertRaises(PermissionError, realpath, ABSTFN + '/missing',
888 strict=ALL_BUT_LAST)
889 self.assertRaises(PermissionError, realpath, ABSTFN + '/missing',
890 strict=ALLOW_MISSING)
891 finally:
892 os.chmod(ABSTFN, 0o755)
893 os_helper.rmdir(ABSTFN + '/k')
894 os_helper.rmdir(ABSTFN)
895
896 @skip_if_ABSTFN_contains_backslash
897 def test_realpath_nonterminal_file(self):

Callers

nothing calls this directly

Calls 8

realpathFunction · 0.90
skipTestMethod · 0.80
rmdirMethod · 0.80
mkdirMethod · 0.45
chmodMethod · 0.45
assertEqualMethod · 0.45
statMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected