Skip to content

Commit

Permalink
Issue python#20055: Fix test_shutil under Windows with symlink privil…
Browse files Browse the repository at this point in the history
…eges held.

Patch by Vajrasky Kok.
  • Loading branch information
pitrou committed Jan 1, 2014
1 parent b075cc0 commit 3f48ac9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
32 changes: 19 additions & 13 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,20 @@ def test_copymode_follow_symlinks(self):
self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
shutil.copymode(src, dst)
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
# follow src link
os.chmod(dst, stat.S_IRWXO)
shutil.copymode(src_link, dst)
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
# follow dst link
os.chmod(dst, stat.S_IRWXO)
shutil.copymode(src, dst_link)
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
# follow both links
os.chmod(dst, stat.S_IRWXO)
shutil.copymode(src_link, dst)
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
# On Windows, os.chmod does not follow symlinks (issue #15411)
if os.name != 'nt':
# follow src link
os.chmod(dst, stat.S_IRWXO)
shutil.copymode(src_link, dst)
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
# follow dst link
os.chmod(dst, stat.S_IRWXO)
shutil.copymode(src, dst_link)
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
# follow both links
os.chmod(dst, stat.S_IRWXO)
shutil.copymode(src_link, dst_link)
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)

@unittest.skipUnless(hasattr(os, 'lchmod'), 'requires os.lchmod')
@support.skip_unless_symlink
Expand Down Expand Up @@ -1543,7 +1545,11 @@ def test_move_dangling_symlink(self):
dst_link = os.path.join(self.dst_dir, 'quux')
shutil.move(dst, dst_link)
self.assertTrue(os.path.islink(dst_link))
self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link))
# On Windows, os.path.realpath does not follow symlinks (issue #9949)
if os.name == 'nt':
self.assertEqual(os.path.realpath(src), os.readlink(dst_link))
else:
self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link))

@support.skip_unless_symlink
@mock_rename
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ IDLE
Tests
-----

- Issue #20055: Fix test_shutil under Windows with symlink privileges held.
Patch by Vajrasky Kok.

- Issue #19938: Re-enabled test_bug_1333982 in test_dis, which had been
disabled since 3.0 due to the changes in listcomp handling.

Expand Down

0 comments on commit 3f48ac9

Please sign in to comment.