@@ -2922,7 +2922,16 @@ def test_delete_missing(self):
29222922 filename = tmp / 'foo'
29232923 self .assertRaises (FileNotFoundError , filename ._delete )
29242924
2925- def setUpWalk (self ):
2925+
2926+ class DummyPathWalkTest (unittest .TestCase ):
2927+ cls = DummyPath
2928+ base = DummyPathTest .base
2929+ can_symlink = False
2930+
2931+ def setUp (self ):
2932+ name = self .id ().split ('.' )[- 1 ]
2933+ if name in _tests_needing_symlinks and not self .can_symlink :
2934+ self .skipTest ('requires symlinks' )
29262935 # Build:
29272936 # TESTFN/
29282937 # TEST1/ a file kid and two directory kids
@@ -2966,8 +2975,11 @@ def setUpWalk(self):
29662975 else :
29672976 self .sub2_tree = (self .sub2_path , [], ["tmp3" ])
29682977
2978+ def tearDown (self ):
2979+ base = self .cls (self .base )
2980+ base ._rmtree ()
2981+
29692982 def test_walk_topdown (self ):
2970- self .setUpWalk ()
29712983 walker = self .walk_path .walk ()
29722984 entry = next (walker )
29732985 entry [1 ].sort () # Ensure we visit SUB1 before SUB2
@@ -2984,7 +2996,6 @@ def test_walk_topdown(self):
29842996 next (walker )
29852997
29862998 def test_walk_prune (self ):
2987- self .setUpWalk ()
29882999 # Prune the search.
29893000 all = []
29903001 for root , dirs , files in self .walk_path .walk ():
@@ -3001,7 +3012,6 @@ def test_walk_prune(self):
30013012 self .assertEqual (all [1 ], self .sub2_tree )
30023013
30033014 def test_walk_bottom_up (self ):
3004- self .setUpWalk ()
30053015 seen_testfn = seen_sub1 = seen_sub11 = seen_sub2 = False
30063016 for path , dirnames , filenames in self .walk_path .walk (top_down = False ):
30073017 if path == self .walk_path :
@@ -3036,7 +3046,6 @@ def test_walk_bottom_up(self):
30363046
30373047 @needs_symlinks
30383048 def test_walk_follow_symlinks (self ):
3039- self .setUpWalk ()
30403049 walk_it = self .walk_path .walk (follow_symlinks = True )
30413050 for root , dirs , files in walk_it :
30423051 if root == self .link_path :
@@ -3048,7 +3057,6 @@ def test_walk_follow_symlinks(self):
30483057
30493058 @needs_symlinks
30503059 def test_walk_symlink_location (self ):
3051- self .setUpWalk ()
30523060 # Tests whether symlinks end up in filenames or dirnames depending
30533061 # on the `follow_symlinks` argument.
30543062 walk_it = self .walk_path .walk (follow_symlinks = False )
@@ -3097,5 +3105,10 @@ class DummyPathWithSymlinksTest(DummyPathTest):
30973105 can_symlink = True
30983106
30993107
3108+ class DummyPathWithSymlinksWalkTest (DummyPathWalkTest ):
3109+ cls = DummyPathWithSymlinks
3110+ can_symlink = True
3111+
3112+
31003113if __name__ == "__main__" :
31013114 unittest .main ()
0 commit comments