8000 Issue #20055: Fix test_shutil under Windows with symlink privileges h… · python/cpython@3f48ac9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f48ac9

Browse files
committed
Issue #20055: Fix test_shutil under Windows with symlink privileges held.
Patch by Vajrasky Kok.
1 parent b075cc0 commit 3f48ac9

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

Lib/test/test_shutil.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -287,18 +287,20 @@ def test_copymode_follow_symlinks(self):
287287
self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
288288
shutil.copymode(src, dst)
289289
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
290-
# follow src link
291-
os.chmod(dst, stat.S_IRWXO)
292-
shutil.copymode(src_link, dst)
293-
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
294-
# follow dst link
295-
os.chmod(dst, stat.S_IRWXO)
296-
shutil.copymode(src, dst_link)
< E880 /td>
297-
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
298-
# follow both links
299-
os.chmod(dst, stat.S_IRWXO)
300-
shutil.copymode(src_link, dst)
301-
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
290+
# On Windows, os.chmod does not follow symlinks (issue #15411)
291+
if os.name != 'nt':
292+
# follow src link
293+
os.chmod(dst, stat.S_IRWXO)
294+
shutil.copymode(src_link, dst)
295+
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
296+
# follow dst link
297+
os.chmod(dst, stat.S_IRWXO)
298+
shutil.copymode(src, dst_link)
299+
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
300+
# follow both links
301+
os.chmod(dst, stat.S_IRWXO)
302+
shutil.copymode(src_link, dst_link)
303+
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
302304

303305
@unittest.skipUnless(hasattr(os, 'lchmod'), 'requires os.lchmod')
304306
@support.skip_unless_symlink
@@ -1543,7 +1545,11 @@ def test_move_dangling_symlink(self):
15431545
dst_link = os.path.join(self.dst_dir, 'quux')
15441546
shutil.move(dst, dst_link)
15451547
self.assertTrue(os.path.islink(dst_link))
1546-
self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link))
1548+
# On Windows, os.path.realpath does not follow symlinks (issue #9949)
1549+
if os.name == 'nt':
1550+
self.assertEqual(os.path.realpath(src), os.readlink(dst_link))
1551+
else:
1552+
self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link))
15471553

15481554
@support.skip_unless_symlink
15491555
@mock_rename

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ IDLE
197197
Tests
198198
-----
199199

200+
- Issue #20055: Fix test_shutil under Windows with symlink privileges held.
201+
Patch by Vajrasky Kok.
202+
200203
- Issue #19938: Re-enabled test_bug_1333982 in test_dis, which had been
201204
disabled since 3.0 due to the changes in listcomp handling.
202205

0 commit comments

Comments
 (0)
0