11import sys
22import os
33import io
4- import shutil
54from hashlib import md5
65
76import unittest
@@ -480,16 +479,16 @@ def test_extract_hardlink(self):
480479 # Test hardlink extraction (e.g. bug #857297).
481480 with tarfile .open (tarname , errorlevel = 1 , encoding = "iso8859-1" ) as tar :
482481 tar .extract ("ustar/regtype" , TEMPDIR )
483- self .addCleanup (os . remove , os .path .join (TEMPDIR , "ustar/regtype" ))
482+ self .addCleanup (support . unlink , os .path .join (TEMPDIR , "ustar/regtype" ))
484483
485484 tar .extract ("ustar/lnktype" , TEMPDIR )
486- self .addCleanup (os . remove , os .path .join (TEMPDIR , "ustar/lnktype" ))
485+ self .addCleanup (support . unlink , os .path .join (TEMPDIR , "ustar/lnktype" ))
487486 with open (os .path .join (TEMPDIR , "ustar/lnktype" ), "rb" ) as f :
488487 data = f .read ()
489488 self .assertEqual (md5sum (data ), md5_regtype )
490489
491490 tar .extract ("ustar/symtype" , TEMPDIR )
492- self .addCleanup (os . remove , os .path .join (TEMPDIR , "ustar/symtype" ))
491+ self .addCleanup (support . unlink , os .path .join (TEMPDIR , "ustar/symtype" ))
493492 with open (os .path .join (TEMPDIR , "ustar/symtype" ), "rb" ) as f :
494493 data = f .read ()
495494 self .assertEqual (md5sum (data ), md5_regtype )
@@ -522,7 +521,7 @@ def format_mtime(mtime):
522521 self .assertEqual (tarinfo .mtime , file_mtime , errmsg )
523522 finally :
524523 tar .close ()
525- shutil .rmtree (DIR )
524+ support .rmtree (DIR )
526525
527526 def test_extract_directory (self ):
528527 dirtype = "ustar/dirtype"
@@ -537,7 +536,7 @@ def test_extract_directory(self):
537536 if sys .platform != "win32" :
538537 self .assertEqual (os .stat (extracted ).st_mode & 0o777 , 0o755 )
539538 finally :
540- shutil .rmtree (DIR )
539+ support .rmtree (DIR )
541540
542541 def test_init_close_fobj (self ):
543542 # Issue #7341: Close the internal file object in the TarFile
@@ -901,7 +900,7 @@ def _fs_supports_holes():
901900 fobj .seek (4096 )
902901 fobj .truncate ()
903902 s = os .stat (name )
904- os . remove (name )
903+ support . unlink (name )
905904 return s .st_blocks == 0
906905 else :
907906 return False
@@ -1034,7 +1033,7 @@ def test_directory_size(self):
10341033 finally :
10351034 tar .close ()
10361035 finally :
1037- os .rmdir (path )
1036+ support .rmdir (path )
10381037
10391038 @unittest .skipUnless (hasattr (os , "link" ),
10401039 "Missing hardlink implementation" )
@@ -1054,8 +1053,8 @@ def test_link_size(self):
10541053 finally :
10551054 tar .close ()
10561055 finally :
1057- os . remove (target )
1058- os . remove (link )
1056+ support . unlink (target )
1057+ support . unlink (link )
10591058
10601059 @support .skip_unless_symlink
10611060 def test_symlink_size (self ):
@@ -1069,7 +1068,7 @@ def test_symlink_size(self):
10691068 finally :
10701069 tar .close ()
10711070 finally :
1072- os . remove (path )
1071+ support . unlink (path )
10731072
10741073 def test_add_self (self ):
10751074 # Test for #1257255.
@@ -1116,7 +1115,7 @@ def test_exclude(self):
11161115 finally :
11171116 tar .close ()
11181117 finally :
1119- shutil .rmtree (tempdir )
1118+ support .rmtree (tempdir )
11201119
11211120 def test_filter (self ):
11221121 tempdir = os .path .join (TEMPDIR , "filter" )
@@ -1152,7 +1151,7 @@ def filter(tarinfo):
11521151 finally :
11531152 tar .close ()
11541153 finally :
1155- shutil .rmtree (tempdir )
1154+ support .rmtree (tempdir )
11561155
11571156 # Guarantee that stored pathnames are not modified. Don't
11581157 # remove ./ or ../ or double slashes. Still make absolute
@@ -1180,9 +1179,9 @@ def _test_pathname(self, path, cmp_path=None, dir=False):
11801179 tar .close ()
11811180
11821181 if not dir :
1183- os . remove (foo )
1182+ support . unlink (foo )
11841183 else :
1185- os .rmdir (foo )
1184+ support .rmdir (foo )
11861185
11871186 self .assertEqual (t .name , cmp_path or path .replace (os .sep , "/" ))
11881187
@@ -1213,8 +1212,8 @@ def test_extractall_symlinks(self):
12131212 finally :
12141213 tar .close ()
12151214 finally :
1216- os .unlink (temparchive )
1217- shutil .rmtree (tempdir )
1215+ support .unlink (temparchive )
1216+ support .rmtree (tempdir )
12181217
12191218 def test_pathnames (self ):
12201219 self ._test_pathname ("foo" )
@@ -1314,7 +1313,7 @@ def test_file_mode(self):
13141313 # Test for issue #8464: Create files with correct
13151314 # permissions.
13161315 if os .path .exists (tmpname ):
1317- os . remove (tmpname )
1316+ support . unlink (tmpname )
13181317
13191318 original_umask = os .umask (0o022 )
13201319 try :
@@ -1668,7 +1667,7 @@ class AppendTestBase:
16681667 def setUp (self ):
16691668 self .tarname = tmpname
16701669 if os .path .exists (self .tarname ):
1671- os . remove (self .tarname )
1670+ support . unlink (self .tarname )
16721671
16731672 def _create_testtar (self , mode = "w:" ):
16741673 with tarfile .open (tarname , encoding = "iso8859-1" ) as src :
@@ -2175,7 +2174,7 @@ def setUpModule():
21752174
21762175def tearDownModule ():
21772176 if os .path .exists (TEMPDIR ):
2178- shutil .rmtree (TEMPDIR )
2177+ support .rmtree (TEMPDIR )
21792178
21802179if __name__ == "__main__" :
21812180 unittest .main ()
0 commit comments