11import sys
22import os
33import io
4- import shutil
54from hashlib import md5
65
76import unittest
@@ -456,16 +455,16 @@ def test_extract_hardlink(self):
456455 # Test hardlink extraction (e.g. bug #857297).
457456 with tarfile .open (tarname , errorlevel = 1 , encoding = "iso8859-1" ) as tar :
458457 tar .extract ("ustar/regtype" , TEMPDIR )
459- self .addCleanup (os . remove , os .path .join (TEMPDIR , "ustar/regtype" ))
458+ self .addCleanup (support . unlink , os .path .join (TEMPDIR , "ustar/regtype" ))
460459
461460 tar .extract ("ustar/lnktype" , TEMPDIR )
462- self .addCleanup (os . remove , os .path .join (TEMPDIR , "ustar/lnktype" ))
461+ self .addCleanup (support . unlink , os .path .join (TEMPDIR , "ustar/lnktype" ))
463462 with open (os .path .join (TEMPDIR , "ustar/lnktype" ), "rb" ) as f :
464463 data = f .read ()
465464 self .assertEqual (md5sum (data ), md5_regtype )
466465
467466 tar .extract ("ustar/symtype" , TEMPDIR )
468- self .addCleanup (os . remove , os .path .join (TEMPDIR , "ustar/symtype" ))
467+ self .addCleanup (support . unlink , os .path .join (TEMPDIR , "ustar/symtype" ))
469468 with open (os .path .join (TEMPDIR , "ustar/symtype" ), "rb" ) as f :
470469 data = f .read ()
471470 self .assertEqual (md5sum (data ), md5_regtype )
@@ -498,7 +497,7 @@ def format_mtime(mtime):
498497 self .assertEqual (tarinfo .mtime , file_mtime , errmsg )
499498 finally :
500499 tar .close ()
501- shutil .rmtree (DIR )
500+ support .rmtree (DIR )
502501
503502 def test_extract_directory (self ):
504503 dirtype = "ustar/dirtype"
@@ -513,7 +512,7 @@ def test_extract_directory(self):
513512 if sys .platform != "win32" :
514513 self .assertEqual (os .stat (extracted ).st_mode & 0o777 , 0o755 )
515514 finally :
516- shutil .rmtree (DIR )
515+ support .rmtree (DIR )
517516
518517 def test_init_close_fobj (self ):
519518 # Issue #7341: Close the internal file object in the TarFile
@@ -877,7 +876,7 @@ def _fs_supports_holes():
877876 fobj .seek (4096 )
878877 fobj .truncate ()
879878 s = os .stat (name )
880- os . remove (name )
879+ support . unlink (name )
881880 return s .st_blocks == 0
882881 else :
883882 return False
@@ -1010,7 +1009,7 @@ def test_directory_size(self):
10101009 finally :
10111010 tar .close ()
10121011 finally :
1013- os .rmdir (path )
1012+ support .rmdir (path )
10141013
10151014 @unittest .skipUnless (hasattr (os , "link" ),
10161015 "Missing hardlink implementation" )
@@ -1030,8 +1029,8 @@ def test_link_size(self):
10301029 finally :
10311030 tar .close ()
10321031 finally :
1033- os . remove (target )
1034- os . remove (link )
1032+ support . unlink (target )
1033+ support . unlink (link )
10351034
10361035 @support .skip_unless_symlink
10371036 def test_symlink_size (self ):
@@ -1045,7 +1044,7 @@ def test_symlink_size(self):
10451044 finally :
10461045 tar .close ()
10471046 finally :
1048- os . remove (path )
1047+ support . unlink (path )
10491048
10501049 def test_add_self (self ):
10511050 # Test for #1257255.
@@ -1092,7 +1091,7 @@ def test_exclude(self):
10921091 finally :
10931092 tar .close ()
10941093 finally :
1095- shutil .rmtree (tempdir )
1094+ support .rmtree (tempdir )
10961095
10971096 def test_filter (self ):
10981097 tempdir = os .path .join (TEMPDIR , "filter" )
@@ -1128,7 +1127,7 @@ def filter(tarinfo):
11281127 finally :
11291128 tar .close ()
11301129 finally :
1131- shutil .rmtree (tempdir )
1130+ support .rmtree (tempdir )
11321131
11331132 # Guarantee that stored pathnames are not modified. Don't
11341133 # remove ./ or ../ or double slashes. Still make absolute
@@ -1156,9 +1155,9 @@ def _test_pathname(self, path, cmp_path=None, dir=False):
11561155 tar .close ()
11571156
11581157 if not dir :
1159- os . remove (foo )
1158+ support . unlink (foo )
11601159 else :
1161- os .rmdir (foo )
1160+ support .rmdir (foo )
11621161
11631162 self .assertEqual (t .name , cmp_path or path .replace (os .sep , "/" ))
11641163
@@ -1189,8 +1188,8 @@ def test_extractall_symlinks(self):
11891188 finally :
11901189 tar .close ()
11911190 finally :
1192- os .unlink (temparchive )
1193- shutil .rmtree (tempdir )
1191+ support .unlink (temparchive )
1192+ support .rmtree (tempdir )
11941193
11951194 def test_pathnames (self ):
11961195 self ._test_pathname ("foo" )
@@ -1290,7 +1289,7 @@ def test_file_mode(self):
12901289 # Test for issue #8464: Create files with correct
12911290 # permissions.
12921291 if os .path .exists (tmpname ):
1293- os . remove (tmpname )
1292+ support . unlink (tmpname )
12941293
12951294 original_umask = os .umask (0o022 )
12961295 try :
@@ -1644,7 +1643,7 @@ class AppendTestBase:
16441643 def setUp (self ):
16451644 self .tarname = tmpname
16461645 if os .path .exists (self .tarname ):
1647- os . remove (self .tarname )
1646+ support . unlink (self .tarname )
16481647
16491648 def _create_testtar (self , mode = "w:" ):
16501649 with tarfile .open (tarname , encoding = "iso8859-1" ) as src :
@@ -2151,7 +2150,7 @@ def setUpModule():
21512150
21522151def tearDownModule ():
21532152 if os .path .exists (TEMPDIR ):
2154- shutil .rmtree (TEMPDIR )
2153+ support .rmtree (TEMPDIR )
21552154
21562155if __name__ == "__main__" :
21572156 unittest .main ()
0 commit comments