Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests on Windows.
  • Loading branch information
serhiy-storchaka committed Dec 13, 2023
commit a69e8cc7e44fdb048e58cb574ccf5fad1f6761ec
30 changes: 18 additions & 12 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,16 +940,18 @@ def test_utime(self):
def check_chmod(self, chmod_func, target, **kwargs):
mode = os.stat(target).st_mode
try:
chmod_func(target, mode & ~stat.S_IWRITE, **kwargs)
self.assertEqual(os.stat(target).st_mode, mode & ~stat.S_IWRITE)
new_mode = mode & ~(stat.S_IWOTH | stat.S_IWGRP | stat.S_IWUSR)
chmod_func(target, new_mode, **kwargs)
self.assertEqual(os.stat(target).st_mode, new_mode)
if stat.S_ISREG(mode):
try:
with open(target, 'wb+'):
pass
except PermissionError:
pass
chmod_func(target, mode | stat.S_IWRITE, **kwargs)
self.assertEqual(os.stat(target).st_mode, mode | stat.S_IWRITE)
new_mode = mode | (stat.S_IWOTH | stat.S_IWGRP | stat.S_IWUSR)
chmod_func(target, new_mode, **kwargs)
self.assertEqual(os.stat(target).st_mode, new_mode)
if stat.S_ISREG(mode):
with open(target, 'wb+'):
pass
Expand Down Expand Up @@ -984,24 +986,28 @@ def check_chmod_link(self, chmod_func, target, link, **kwargs):
target_mode = os.stat(target).st_mode
link_mode = os.lstat(link).st_mode
try:
chmod_func(link, target_mode & ~stat.S_IWRITE, **kwargs)
self.assertEqual(os.stat(target).st_mode, target_mode & ~stat.S_IWRITE)
new_mode = target_mode & ~(stat.S_IWOTH | stat.S_IWGRP | stat.S_IWUSR)
chmod_func(link, new_mode, **kwargs)
self.assertEqual(os.stat(target).st_mode, new_mode)
self.assertEqual(os.lstat(link).st_mode, link_mode)
chmod_func(link, target_mode | stat.S_IWRITE)
self.assertEqual(os.stat(target).st_mode, target_mode | stat.S_IWRITE)
new_mode = target_mode | (stat.S_IWOTH | stat.S_IWGRP | stat.S_IWUSR)
chmod_func(link, new_mode, **kwargs)
self.assertEqual(os.stat(target).st_mode, new_mode)
self.assertEqual(os.lstat(link).st_mode, link_mode)
finally:
posix.chmod(target, target_mode)

def check_lchmod_link(self, chmod_func, target, link, **kwargs):
target_mode = os.stat(target).st_mode
link_mode = os.lstat(link).st_mode
chmod_func(link, link_mode & ~stat.S_IWRITE, **kwargs)
new_mode = link_mode & ~(stat.S_IWOTH | stat.S_IWGRP | stat.S_IWUSR)
chmod_func(link, new_mode, **kwargs)
self.assertEqual(os.stat(target).st_mode, target_mode)
self.assertEqual(os.lstat(link).st_mode, link_mode & ~stat.S_IWRITE)
chmod_func(link, link_mode | stat.S_IWRITE)
self.assertEqual(os.lstat(link).st_mode, new_mode)
new_mode = link_mode | (stat.S_IWOTH | stat.S_IWGRP | stat.S_IWUSR)
chmod_func(link, new_mode, **kwargs)
self.assertEqual(os.stat(target).st_mode, target_mode)
self.assertEqual(os.lstat(link).st_mode, link_mode | stat.S_IWRITE)
self.assertEqual(os.lstat(link).st_mode, new_mode)

@os_helper.skip_unless_symlink
def test_chmod_file_symlink(self):
Expand Down
2 changes: 1 addition & 1 deletion Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.