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()