bpo-39906: Add follow_symlinks parameter to pathlib.Path.stat() and chmod() (GH-18864)

This commit is contained in:
Barney Gale 2021-04-07 16:53:39 +01:00 committed by GitHub
parent 7a7ba3d343
commit abf964942f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 17 deletions

View file

@ -1828,6 +1828,21 @@ class _BasePathTest(object):
p.chmod(new_mode)
self.assertEqual(p.stat().st_mode, new_mode)
# On Windows, os.chmod does not follow symlinks (issue #15411)
@only_posix
def test_chmod_follow_symlinks_true(self):
p = self.cls(BASE) / 'linkA'
q = p.resolve()
mode = q.stat().st_mode
# Clear writable bit.
new_mode = mode & ~0o222
p.chmod(new_mode, follow_symlinks=True)
self.assertEqual(q.stat().st_mode, new_mode)
# Set writable bit
new_mode = mode | 0o222
p.chmod(new_mode, follow_symlinks=True)
self.assertEqual(q.stat().st_mode, new_mode)
# XXX also need a test for lchmod.
def test_stat(self):
@ -1839,6 +1854,17 @@ class _BasePathTest(object):
self.addCleanup(p.chmod, st.st_mode)
self.assertNotEqual(p.stat(), st)
@os_helper.skip_unless_symlink
def test_stat_no_follow_symlinks(self):
p = self.cls(BASE) / 'linkA'
st = p.stat()
self.assertNotEqual(st, p.stat(follow_symlinks=False))
def test_stat_no_follow_symlinks_nosymlink(self):
p = self.cls(BASE) / 'fileA'
st = p.stat()
self.assertEqual(st, p.stat(follow_symlinks=False))
@os_helper.skip_unless_symlink
def test_lstat(self):
p = self.cls(BASE)/ 'linkA'