mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-39906: Add follow_symlinks parameter to pathlib.Path.stat() and chmod() (GH-18864)
This commit is contained in:
parent
7a7ba3d343
commit
abf964942f
4 changed files with 49 additions and 17 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue