@@ -1103,33 +1103,36 @@ def test_copytree_subdirectory(self):
11031103
11041104 def test_copytree_to_itself_gives_sensible_error_message (self ):
11051105 base_dir = self .mkdtemp ()
1106+ self .addCleanup (shutil .rmtree , base_dir , ignore_errors = True )
11061107 src_dir = os .path .join (base_dir , "src" )
11071108 os .makedirs (src_dir )
11081109 create_file ((src_dir , "somefilename" ), "somecontent" )
1109- _assert_are_the_same_file_is_raised (src_dir , src_dir )
1110+ self . _assert_are_the_same_file_is_raised (src_dir , src_dir )
11101111
11111112 @os_helper .skip_unless_symlink
11121113 def test_copytree_to_backpointing_symlink_gives_sensible_error_message (self ):
11131114 base_dir = self .mkdtemp ()
1115+ self .addCleanup (shutil .rmtree , base_dir , ignore_errors = True )
11141116 src_dir = os .path .join (base_dir , "src" )
11151117 target_dir = os .path .join (base_dir , "target" )
11161118 os .makedirs (src_dir )
11171119 os .makedirs (target_dir )
11181120 some_file = os .path .join (src_dir , "somefilename" )
11191121 create_file (some_file , "somecontent" )
11201122 os .symlink (some_file , os .path .join (target_dir , "somefilename" ))
1121- _assert_are_the_same_file_is_raised (src_dir , target_dir )
1123+ self ._assert_are_the_same_file_is_raised (src_dir , target_dir )
1124+
1125+ def _assert_are_the_same_file_is_raised (self , src_dir , target_dir ):
1126+ try :
1127+ shutil .copytree (src_dir , target_dir , dirs_exist_ok = True )
1128+ self .fail ("shutil.Error should have been raised" )
1129+ except Error as error :
1130+ self .assertEqual (len (error .args [0 ]), 1 )
1131+ if sys .platform == "win32" :
1132+ self .assertIn ("it is being used by another process" , error .args [0 ][0 ][2 ])
1133+ else :
1134+ self .assertIn ("are the same file" , error .args [0 ][0 ][2 ])
11221135
1123- def _assert_are_the_same_file_is_raised (src_dir , target_dir ):
1124- try :
1125- shutil .copytree (src_dir , target_dir , dirs_exist_ok = True )
1126- raise Exception ("copytree did not raise" )
1127- except Error as error :
1128- assert len (error .args [0 ]) == 1
1129- if sys .platform == "win32" :
1130- assert "it is being used by another process" in error .args [0 ][0 ][2 ]
1131- else :
1132- assert "are the same file" in error .args [0 ][0 ][2 ]
11331136
11341137class TestCopy (BaseTest , unittest .TestCase ):
11351138
0 commit comments