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

Method test_realpath_permission

Lib/test/test_ntpath.py:934–976  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

932
933 @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
934 def test_realpath_permission(self):
935 # Test whether python can resolve the real filename of a
936 # shortened file name even if it does not have permission to access it.
937 ABSTFN = ntpath.realpath(os_helper.TESTFN)
938
939 os_helper.unlink(ABSTFN)
940 os_helper.rmtree(ABSTFN)
941 os.mkdir(ABSTFN)
942 self.addCleanup(os_helper.rmtree, ABSTFN)
943
944 test_file = ntpath.join(ABSTFN, "LongFileName123.txt")
945 test_file_short = ntpath.join(ABSTFN, "LONGFI~1.TXT")
946
947 with open(test_file, "wb") as f:
948 f.write(b"content")
949 # Automatic generation of short names may be disabled on
950 # NTFS volumes for the sake of performance.
951 # They're not supported at all on ReFS and exFAT.
952 p = subprocess.run(
953 # Try to set the short name manually.
954 ['fsutil.exe', 'file', 'setShortName', test_file, 'LONGFI~1.TXT'],
955 creationflags=subprocess.DETACHED_PROCESS
956 )
957
958 if p.returncode:
959 raise unittest.SkipTest('failed to set short name')
960
961 try:
962 self.assertPathEqual(test_file, ntpath.realpath(test_file_short))
963 except AssertionError:
964 raise unittest.SkipTest('the filesystem seems to lack support for short filenames')
965
966 # Deny the right to [S]YNCHRONIZE on the file to
967 # force nt._getfinalpathname to fail with ERROR_ACCESS_DENIED.
968 p = subprocess.run(
969 ['icacls.exe', test_file, '/deny', '*S-1-5-32-545:(S)'],
970 creationflags=subprocess.DETACHED_PROCESS
971 )
972
973 if p.returncode:
974 raise unittest.SkipTest('failed to deny access to the test file')
975
976 self.assertPathEqual(test_file, ntpath.realpath(test_file_short))
977
978 def test_expandvars(self):
979 with os_helper.EnvironmentVarGuard() as env:

Callers

nothing calls this directly

Calls 9

realpathMethod · 0.80
addCleanupMethod · 0.80
openFunction · 0.50
unlinkMethod · 0.45
mkdirMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45
runMethod · 0.45
assertPathEqualMethod · 0.45

Tested by

no test coverage detected