mirror of https://github.com/python/cpython
GH-85633: Fix pathlib test failures on filesystems without world-write. (#122883)
Replace `umask(0)` with `umask(0o002)` so the created files are not world-writable, and replace `umask(0o022)` with `umask(0o026)` to check that permissions for 'others' can still be set.
This commit is contained in:
parent
901d94992e
commit
5f68511522
|
@ -1605,18 +1605,20 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
|
||||||
)
|
)
|
||||||
@needs_posix
|
@needs_posix
|
||||||
def test_open_mode(self):
|
def test_open_mode(self):
|
||||||
old_mask = os.umask(0)
|
# Unmask all permissions except world-write, which may
|
||||||
|
# not be supported on some filesystems (see GH-85633.)
|
||||||
|
old_mask = os.umask(0o002)
|
||||||
self.addCleanup(os.umask, old_mask)
|
self.addCleanup(os.umask, old_mask)
|
||||||
p = self.cls(self.base)
|
p = self.cls(self.base)
|
||||||
with (p / 'new_file').open('wb'):
|
with (p / 'new_file').open('wb'):
|
||||||
pass
|
pass
|
||||||
st = os.stat(self.parser.join(self.base, 'new_file'))
|
st = os.stat(self.parser.join(self.base, 'new_file'))
|
||||||
self.assertEqual(stat.S_IMODE(st.st_mode), 0o666)
|
self.assertEqual(stat.S_IMODE(st.st_mode), 0o664)
|
||||||
os.umask(0o022)
|
os.umask(0o026)
|
||||||
with (p / 'other_new_file').open('wb'):
|
with (p / 'other_new_file').open('wb'):
|
||||||
pass
|
pass
|
||||||
st = os.stat(self.parser.join(self.base, 'other_new_file'))
|
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
|
@needs_posix
|
||||||
def test_resolve_root(self):
|
def test_resolve_root(self):
|
||||||
|
@ -1634,16 +1636,18 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
|
||||||
)
|
)
|
||||||
@needs_posix
|
@needs_posix
|
||||||
def test_touch_mode(self):
|
def test_touch_mode(self):
|
||||||
old_mask = os.umask(0)
|
# Unmask all permissions except world-write, which may
|
||||||
|
# not be supported on some filesystems (see GH-85633.)
|
||||||
|
old_mask = os.umask(0o002)
|
||||||
self.addCleanup(os.umask, old_mask)
|
self.addCleanup(os.umask, old_mask)
|
||||||
p = self.cls(self.base)
|
p = self.cls(self.base)
|
||||||
(p / 'new_file').touch()
|
(p / 'new_file').touch()
|
||||||
st = os.stat(self.parser.join(self.base, 'new_file'))
|
st = os.stat(self.parser.join(self.base, 'new_file'))
|
||||||
self.assertEqual(stat.S_IMODE(st.st_mode), 0o666)
|
self.assertEqual(stat.S_IMODE(st.st_mode), 0o664)
|
||||||
os.umask(0o022)
|
os.umask(0o026)
|
||||||
(p / 'other_new_file').touch()
|
(p / 'other_new_file').touch()
|
||||||
st = os.stat(self.parser.join(self.base, 'other_new_file'))
|
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)
|
||||||
(p / 'masked_new_file').touch(mode=0o750)
|
(p / 'masked_new_file').touch(mode=0o750)
|
||||||
st = os.stat(self.parser.join(self.base, 'masked_new_file'))
|
st = os.stat(self.parser.join(self.base, 'masked_new_file'))
|
||||||
self.assertEqual(stat.S_IMODE(st.st_mode), 0o750)
|
self.assertEqual(stat.S_IMODE(st.st_mode), 0o750)
|
||||||
|
|
Loading…
Reference in New Issue