fix "py.cleanup -d" - add test and check to only remove empty dirs (!)

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-10-27 16:03:14 +01:00
parent 09ba42a1bb
commit 2b1505c0f3
2 changed files with 10 additions and 7 deletions

View File

@ -35,7 +35,8 @@ def main():
if options.removedir:
for x in path.visit(lambda x: x.check(dir=1),
lambda x: x.check(dotfile=0, link=0)):
remove(x, options)
if not x.listdir():
remove(x, options)
def remove(path, options):
if options.dryrun:

View File

@ -38,12 +38,14 @@ class TestPyCleanup:
result = testdir.runpybin("py.cleanup", tmpdir)
assert not pyc.check()
def test_dir_remove(self, testdir, tmpdir):
p = tmpdir.mkdir("a")
result = testdir.runpybin("py.cleanup", tmpdir)
def test_dir_remove_simple(self, testdir, tmpdir):
subdir = tmpdir.mkdir("subdir")
p = subdir.ensure("file")
result = testdir.runpybin("py.cleanup", "-d", tmpdir)
assert result.ret == 0
assert p.check()
assert subdir.check()
p.remove()
p = tmpdir.mkdir("hello")
result = testdir.runpybin("py.cleanup", tmpdir, '-d')
assert result.ret == 0
assert not p.check()
assert not subdir.check()