@@ -869,13 +869,23 @@ def setUp(self):
869869 os .symlink ('broken' , broken_link_path , True )
870870 os .symlink (join ('tmp3' , 'broken' ), broken_link2_path , True )
871871 os .symlink (join ('SUB21' , 'tmp5' ), broken_link3_path , True )
872- self .sub2_tree = (sub2_path , ["link " , "SUB21 " ],
872+ self .sub2_tree = (sub2_path , ["SUB21 " , "link " ],
873873 ["broken_link" , "broken_link2" , "broken_link3" ,
874874 "tmp3" ])
875875 else :
876876 self .sub2_tree = (sub2_path , [], ["tmp3" ])
877877
878878 os .chmod (self .sub21_path , 0 )
879+ try :
880+ os .listdir (self .sub21_path )
881+ except PermissionError :
882+ pass
883+ else :
884+ os .chmod (self .sub21_path , stat .S_IRWXU )
885+ os .unlink (tmp5_path )
886+ os .rmdir (self .sub21_path )
887+ self .sub21_path = None
888+ del self .sub2_tree [1 ][:1 ]
879889
880890 def test_walk_topdown (self ):
881891 # Walk top-down.
@@ -888,6 +898,7 @@ def test_walk_topdown(self):
888898 flipped = all [0 ][1 ][0 ] != "SUB1"
889899 all [0 ][1 ].sort ()
890900 all [3 - 2 * flipped ][- 1 ].sort ()
901+ all [3 - 2 * flipped ][1 ].sort ()
891902 self .assertEqual (all [0 ], (self .walk_path , ["SUB1" , "SUB2" ], ["tmp1" ]))
892903 self .assertEqual (all [1 + flipped ], (self .sub1_path , ["SUB11" ], ["tmp2" ]))
893904 self .assertEqual (all [2 + flipped ], (self .sub11_path , [], []))
@@ -908,6 +919,7 @@ def test_walk_prune(self):
908919 (self .walk_path , ["SUB2" ], ["tmp1" ]))
909920
910921 all [1 ][- 1 ].sort ()
922+ all [1 ][1 ].sort ()
911923 self .assertEqual (all [1 ], self .sub2_tree )
912924
913925 def test_walk_bottom_up (self ):
@@ -921,6 +933,7 @@ def test_walk_bottom_up(self):
921933 flipped = all [3 ][1 ][0 ] != "SUB1"
922934 all [3 ][1 ].sort ()
923935 all [2 - 2 * flipped ][- 1 ].sort ()
936+ all [2 - 2 * flipped ][1 ].sort ()
924937 self .assertEqual (all [3 ],
925938 (self .walk_path , ["SUB1" , "SUB2" ], ["tmp1" ]))
926939 self .assertEqual (all [flipped ],
@@ -949,7 +962,8 @@ def tearDown(self):
949962 # Windows, which doesn't have a recursive delete command. The
950963 # (not so) subtlety is that rmdir will fail unless the dir's
951964 # kids are removed first, so bottom up is essential.
952- os .chmod (self .sub21_path , stat .S_IRWXU )
965+ if self .sub21_path :
966+ os .chmod (self .sub21_path , stat .S_IRWXU )
953967 for root , dirs , files in os .walk (support .TESTFN , topdown = False ):
954968 for name in files :
955969 os .remove (os .path .join (root , name ))
@@ -1045,7 +1059,8 @@ def test_fd_leak(self):
10451059
10461060 def tearDown (self ):
10471061 # cleanup
1048- os .chmod (self .sub21_path , stat .S_IRWXU )
1062+ if self .sub21_path :
1063+ os .chmod (self .sub21_path , stat .S_IRWXU )
10491064 for root , dirs , files , rootfd in os .fwalk (support .TESTFN , topdown = False ):
10501065 for name in files :
10511066 os .unlink (name , dir_fd = rootfd )
0 commit comments