1-
21# Copyright (C) 2003 Python Software Foundation
32
43import unittest
@@ -20,21 +19,28 @@ def test_rmtree_errors(self):
2019 def test_on_error (self ):
2120 self .errorState = 0
2221 os .mkdir (TESTFN )
23- f = open (os .path .join (TESTFN , 'a' ), 'w' )
22+ self .childpath = os .path .join (TESTFN , 'a' )
23+ f = open (self .childpath , 'w' )
2424 f .close ()
25- # Make TESTFN unwritable.
26- os .chmod (TESTFN , stat .S_IRUSR )
25+ old_dir_mode = os .stat (TESTFN ).st_mode
26+ old_child_mode = os .stat (self .childpath ).st_mode
27+ # Make unwritable.
28+ os .chmod (self .childpath , stat .S_IREAD )
29+ os .chmod (TESTFN , stat .S_IREAD )
2730
2831 shutil .rmtree (TESTFN , onerror = self .check_args_to_onerror )
2932
30- # Make TESTFN writable again.
31- os .chmod (TESTFN , stat .S_IRWXU )
33+ # Make writable again.
34+ os .chmod (TESTFN , old_dir_mode )
35+ os .chmod (self .childpath , old_child_mode )
36+
37+ # Clean up.
3238 shutil .rmtree (TESTFN )
3339
3440 def check_args_to_onerror (self , func , arg , exc ):
3541 if self .errorState == 0 :
3642 self .assertEqual (func , os .remove )
37- self .assertEqual (arg , os . path . join ( TESTFN , 'a' ) )
43+ self .assertEqual (arg , self . childpath )
3844 self .assertEqual (exc [0 ], OSError )
3945 self .errorState = 1
4046 else :
0 commit comments