Skip to content

Commit

Permalink
pythonGH-85633: Fix pathlib test failures on filesystems without worl…
Browse files Browse the repository at this point in the history
…d-write.

Replace `umask(0)` with `umask(2)`, and `umask(0o022)` with `umask(0o026)`,
so the created files are not world-writable. In the latter case, we remove
read permission to check that permissions for 'others' can still be set.
  • Loading branch information
barneygale committed Aug 10, 2024
1 parent 0fd97e4 commit 892b4bb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Lib/test/test_pathlib/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,18 +1605,18 @@ def test_absolute_posix(self):
)
@needs_posix
def test_open_mode(self):
old_mask = os.umask(0)
old_mask = os.umask(2)
self.addCleanup(os.umask, old_mask)
p = self.cls(self.base)
with (p / 'new_file').open('wb'):
pass
st = os.stat(self.parser.join(self.base, 'new_file'))
self.assertEqual(stat.S_IMODE(st.st_mode), 0o666)
os.umask(0o022)
self.assertEqual(stat.S_IMODE(st.st_mode), 0o664)
os.umask(0o026)
with (p / 'other_new_file').open('wb'):
pass
st = os.stat(self.parser.join(self.base, 'other_new_file'))
self.assertEqual(stat.S_IMODE(st.st_mode), 0o644)
self.assertEqual(stat.S_IMODE(st.st_mode), 0o640)

@needs_posix
def test_resolve_root(self):
Expand Down

0 comments on commit 892b4bb

Please sign in to comment.