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

Method check_chmod

Lib/test/test_os/test_posix.py:1056–1076  ·  view source on GitHub ↗
(self, chmod_func, target, **kwargs)

Source from the content-addressed store, hash-verified

1054 posix.utime(os_helper.TESTFN, (now, now))
1055
1056 def check_chmod(self, chmod_func, target, **kwargs):
1057 closefd = not isinstance(target, int)
1058 mode = os.stat(target).st_mode
1059 try:
1060 new_mode = mode & ~(stat.S_IWOTH | stat.S_IWGRP | stat.S_IWUSR)
1061 chmod_func(target, new_mode, **kwargs)
1062 self.assertEqual(os.stat(target).st_mode, new_mode)
1063 if stat.S_ISREG(mode):
1064 try:
1065 with open(target, 'wb+', closefd=closefd):
1066 pass
1067 except PermissionError:
1068 pass
1069 new_mode = mode | (stat.S_IWOTH | stat.S_IWGRP | stat.S_IWUSR)
1070 chmod_func(target, new_mode, **kwargs)
1071 self.assertEqual(os.stat(target).st_mode, new_mode)
1072 if stat.S_ISREG(mode):
1073 with open(target, 'wb+', closefd=closefd):
1074 pass
1075 finally:
1076 chmod_func(target, mode)
1077
1078 @os_helper.skip_unless_working_chmod
1079 def test_chmod_file(self):

Callers 5

test_chmod_fileMethod · 0.95
test_chmod_dirMethod · 0.95
test_fchmod_fileMethod · 0.95
test_lchmod_fileMethod · 0.95
test_lchmod_dirMethod · 0.95

Calls 4

chmod_funcFunction · 0.85
openFunction · 0.50
statMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected