test_os: use support.rmtree() to cleanup WalkTests
This commit is contained in:
parent
ae39d236b4
commit
3899b549e3
@ -812,6 +812,7 @@ class WalkTests(unittest.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
join = os.path.join
|
join = os.path.join
|
||||||
|
self.addCleanup(support.rmtree, support.TESTFN)
|
||||||
|
|
||||||
# Build:
|
# Build:
|
||||||
# TESTFN/
|
# TESTFN/
|
||||||
@ -922,22 +923,6 @@ class WalkTests(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
self.fail("Didn't follow symlink with followlinks=True")
|
self.fail("Didn't follow symlink with followlinks=True")
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
# Tear everything down. This is a decent use for bottom-up on
|
|
||||||
# Windows, which doesn't have a recursive delete command. The
|
|
||||||
# (not so) subtlety is that rmdir will fail unless the dir's
|
|
||||||
# kids are removed first, so bottom up is essential.
|
|
||||||
for root, dirs, files in os.walk(support.TESTFN, topdown=False):
|
|
||||||
for name in files:
|
|
||||||
os.remove(os.path.join(root, name))
|
|
||||||
for name in dirs:
|
|
||||||
dirname = os.path.join(root, name)
|
|
||||||
if not os.path.islink(dirname):
|
|
||||||
os.rmdir(dirname)
|
|
||||||
else:
|
|
||||||
os.remove(dirname)
|
|
||||||
os.rmdir(support.TESTFN)
|
|
||||||
|
|
||||||
def test_walk_bad_dir(self):
|
def test_walk_bad_dir(self):
|
||||||
# Walk top-down.
|
# Walk top-down.
|
||||||
errors = []
|
errors = []
|
||||||
@ -1020,19 +1005,6 @@ class FwalkTests(WalkTests):
|
|||||||
self.addCleanup(os.close, newfd)
|
self.addCleanup(os.close, newfd)
|
||||||
self.assertEqual(newfd, minfd)
|
self.assertEqual(newfd, minfd)
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
# cleanup
|
|
||||||
for root, dirs, files, rootfd in os.fwalk(support.TESTFN, topdown=False):
|
|
||||||
for name in files:
|
|
||||||
os.unlink(name, dir_fd=rootfd)
|
|
||||||
for name in dirs:
|
|
||||||
st = os.stat(name, dir_fd=rootfd, follow_symlinks=False)
|
|
||||||
if stat.S_ISDIR(st.st_mode):
|
|
||||||
os.rmdir(name, dir_fd=rootfd)
|
|
||||||
else:
|
|
||||||
os.unlink(name, dir_fd=rootfd)
|
|
||||||
os.rmdir(support.TESTFN)
|
|
||||||
|
|
||||||
class BytesWalkTests(WalkTests):
|
class BytesWalkTests(WalkTests):
|
||||||
"""Tests for os.walk() with bytes."""
|
"""Tests for os.walk() with bytes."""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user