From 2b1505c0f323fc554598aaae8ca464f438b3b9be Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 27 Oct 2009 16:03:14 +0100 Subject: [PATCH] fix "py.cleanup -d" - add test and check to only remove empty dirs (!) --HG-- branch : trunk --- _py/cmdline/pycleanup.py | 3 ++- testing/cmdline/test_cmdline.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/_py/cmdline/pycleanup.py b/_py/cmdline/pycleanup.py index 8a933484c..084e59bad 100755 --- a/_py/cmdline/pycleanup.py +++ b/_py/cmdline/pycleanup.py @@ -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: diff --git a/testing/cmdline/test_cmdline.py b/testing/cmdline/test_cmdline.py index 73d1fcfa4..660bf2c07 100644 --- a/testing/cmdline/test_cmdline.py +++ b/testing/cmdline/test_cmdline.py @@ -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()