@@ -877,23 +877,23 @@ def test_copymode_follow_symlinks(self):
877
877
shutil .copymode (src , dst )
878
878
self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
879
879
# On Windows, os.chmod does not follow symlinks (issue #15411)
880
- if os .name != 'nt' :
881
- # follow src link
882
- os .chmod (dst , stat .S_IRWXO )
883
- shutil .copymode (src_link , dst )
884
- self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
885
- # follow dst link
886
- os .chmod (dst , stat .S_IRWXO )
887
- shutil .copymode (src , dst_link )
888
- self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
889
- # follow both links
890
- os .chmod (dst , stat .S_IRWXO )
891
- shutil .copymode (src_link , dst_link )
892
- self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
893
-
894
- @unittest .skipUnless (hasattr (os , 'lchmod' ), 'requires os.lchmod' )
880
+ # follow src link
881
+ os .chmod (dst , stat .S_IRWXO )
882
+ shutil .copymode (src_link , dst )
883
+ self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
884
+ # follow dst link
885
+ os .chmod (dst , stat .S_IRWXO )
886
+ shutil .copymode (src , dst_link )
887
+ self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
888
+ # follow both links
889
+ os .chmod (dst , stat .S_IRWXO )
890
+ shutil .copymode (src_link , dst_link )
891
+ self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
892
+
893
+ @unittest .skipUnless (hasattr (os , 'lchmod' ) or os .name == 'nt' , 'requires os.lchmod' )
895
894
@os_helper .skip_unless_symlink
896
895
def test_copymode_symlink_to_symlink (self ):
896
+ _lchmod = os .chmod if os .name == 'nt' else os .lchmod
897
897
tmp_dir = self .mkdtemp ()
898
898
src = os .path .join (tmp_dir , 'foo' )
899
899
dst = os .path .join (tmp_dir , 'bar' )
@@ -905,20 +905,20 @@ def test_copymode_symlink_to_symlink(self):
905
905
os .symlink (dst , dst_link )
906
906
os .chmod (src , stat .S_IRWXU | stat .S_IRWXG )
907
907
os .chmod (dst , stat .S_IRWXU )
908
- os . lchmod (src_link , stat .S_IRWXO | stat .S_IRWXG )
908
+ _lchmod (src_link , stat .S_IRWXO | stat .S_IRWXG )
909
909
# link to link
910
- os . lchmod (dst_link , stat .S_IRWXO )
910
+ _lchmod (dst_link , stat .S_IRWXO )
911
911
old_mode = os .stat (dst ).st_mode
912
912
shutil .copymode (src_link , dst_link , follow_symlinks = False )
913
913
self .assertEqual (os .lstat (src_link ).st_mode ,
914
914
os .lstat (dst_link ).st_mode )
915
915
self .assertEqual (os .stat (dst ).st_mode , old_mode )
916
916
# src link - use chmod
917
- os . lchmod (dst_link , stat .S_IRWXO )
917
+ _lchmod (dst_link , stat .S_IRWXO )
918
918
shutil .copymode (src_link , dst , follow_symlinks = False )
919
919
self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
920
920
# dst link - use chmod
921
- os . lchmod (dst_link , stat .S_IRWXO )
921
+ _lchmod (dst_link , stat .S_IRWXO )
922
922
shutil .copymode (src , dst_link , follow_symlinks = False )
923
923
self .assertEqual (os .stat (src ).st_mode , os .stat (dst ).st_mode )
924
924
@@ -955,11 +955,13 @@ def test_copystat_symlinks(self):
955
955
os .symlink (dst , dst_link )
956
956
if hasattr (os , 'lchmod' ):
957
957
os .lchmod (src_link , stat .S_IRWXO )
958
+ elif os .name == 'nt' :
959
+ os .chmod (src_link , stat .S_IRWXO )
958
960
if hasattr (os , 'lchflags' ) and hasattr (stat , 'UF_NODUMP' ):
959
961
os .lchflags (src_link , stat .UF_NODUMP )
960
962
src_link_stat = os .lstat (src_link )
961
963
# follow
962
- if hasattr (os , 'lchmod' ):
964
+ if hasattr (os , 'lchmod' ) or os . name == 'nt' :
963
965
shutil .copystat (src_link , dst_link , follow_symlinks = True )
964
966
self .assertNotEqual (src_link_stat .st_mode , os .stat (dst ).st_mode )
965
967
# don't follow
@@ -970,7 +972,7 @@ def test_copystat_symlinks(self):
970
972
# The modification times may be truncated in the new file.
971
973
self .assertLessEqual (getattr (src_link_stat , attr ),
972
974
getattr (dst_link_stat , attr ) + 1 )
973
- if hasattr (os , 'lchmod' ):
975
+ if hasattr (os , 'lchmod' ) or os . name == 'nt' :
974
976
self .assertEqual (src_link_stat .st_mode , dst_link_stat .st_mode )
975
977
if hasattr (os , 'lchflags' ) and hasattr (src_link_stat , 'st_flags' ):
976
978
self .assertEqual (src_link_stat .st_flags , dst_link_stat .st_flags )
0 commit comments