Skip to content

Commit d218810

Browse files
[3.13] GH-85633: Fix pathlib test failures on filesystems without world-write. (GH-122883) (#122979)
GH-85633: Fix pathlib test failures on filesystems without world-write. (GH-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. (cherry picked from commit 5f68511) Co-authored-by: Barney Gale <[email protected]>
1 parent 4aa0e79 commit d218810

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Lib/test/test_pathlib/test_pathlib.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,18 +1296,20 @@ def test_absolute_posix(self):
12961296
)
12971297
@needs_posix
12981298
def test_open_mode(self):
1299-
old_mask = os.umask(0)
1299+
# Unmask all permissions except world-write, which may
1300+
# not be supported on some filesystems (see GH-85633.)
1301+
old_mask = os.umask(0o002)
13001302
self.addCleanup(os.umask, old_mask)
13011303
p = self.cls(self.base)
13021304
with (p / 'new_file').open('wb'):
13031305
pass
13041306
st = os.stat(self.parser.join(self.base, 'new_file'))
1305-
self.assertEqual(stat.S_IMODE(st.st_mode), 0o666)
1306-
os.umask(0o022)
1307+
self.assertEqual(stat.S_IMODE(st.st_mode), 0o664)
1308+
os.umask(0o026)
13071309
with (p / 'other_new_file').open('wb'):
13081310
pass
13091311
st = os.stat(self.parser.join(self.base, 'other_new_file'))
1310-
self.assertEqual(stat.S_IMODE(st.st_mode), 0o644)
1312+
self.assertEqual(stat.S_IMODE(st.st_mode), 0o640)
13111313

13121314
@needs_posix
13131315
def test_resolve_root(self):
@@ -1325,16 +1327,18 @@ def test_resolve_root(self):
13251327
)
13261328
@needs_posix
13271329
def test_touch_mode(self):
1328-
old_mask = os.umask(0)
1330+
# Unmask all permissions except world-write, which may
1331+
# not be supported on some filesystems (see GH-85633.)
1332+
old_mask = os.umask(0o002)
13291333
self.addCleanup(os.umask, old_mask)
13301334
p = self.cls(self.base)
13311335
(p / 'new_file').touch()
13321336
st = os.stat(self.parser.join(self.base, 'new_file'))
1333-
self.assertEqual(stat.S_IMODE(st.st_mode), 0o666)
1334-
os.umask(0o022)
1337+
self.assertEqual(stat.S_IMODE(st.st_mode), 0o664)
1338+
os.umask(0o026)
13351339
(p / 'other_new_file').touch()
13361340
st = os.stat(self.parser.join(self.base, 'other_new_file'))
1337-
self.assertEqual(stat.S_IMODE(st.st_mode), 0o644)
1341+
self.assertEqual(stat.S_IMODE(st.st_mode), 0o640)
13381342
(p / 'masked_new_file').touch(mode=0o750)
13391343
st = os.stat(self.parser.join(self.base, 'masked_new_file'))
13401344
self.assertEqual(stat.S_IMODE(st.st_mode), 0o750)

0 commit comments

Comments
 (0)