Skip to content

Commit

Permalink
Add some testcases for empty dir removal (might need some more even)
Browse files Browse the repository at this point in the history
  • Loading branch information
sahib committed Jun 15, 2017
1 parent 0365cc5 commit a70970f
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/test_formatters/test_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,81 @@ def test_hardlink_duplicate_directories(shell):
full_dupe_a = os.path.join(TESTDIR_NAME, "dir_a/x")
full_dupe_b = os.path.join(TESTDIR_NAME, "dir_b/x")
assert os.stat(full_dupe_a).st_ino == os.stat(full_dupe_b).st_ino


def _check_if_empty_dirs_deleted(shell, inverse_order, sh_path, data):
run_shell_script(shell, sh_path, "-dc")

if inverse_order:
assert not os.path.exists(data[1]["path"])
assert not os.path.exists(os.path.join(TESTDIR_NAME, "deep/a"))
assert os.path.exists(data[0]["path"])
else:
assert os.path.exists(data[0]["path"])
assert not os.path.exists(data[1]["path"])


@parameterized([
("sh", False), ("bash", False), ("dash", False),
("sh", True), ("bash", True), ("dash", True)
])
@with_setup(usual_setup_func, usual_teardown_func)
def test_remove_empty_dirs(shell, inverse_order):
create_file('xxx', 'deep/a/b/c/d/e/1')
create_file('xxx', 'deep/x/2')

sh_path = os.path.join(TESTDIR_NAME, "result.sh")
header, *data, footer = run_rmlint(
"-S {} -o sh:{}".format(
"A" if inverse_order else "a",
sh_path
),
)

assert len(data) == 2

if inverse_order:
assert data[0]["path"].endswith("x/2")
assert data[0]["is_original"] is True
assert data[1]["path"].endswith("e/1")
assert data[1]["is_original"] is False
else:
assert data[0]["path"].endswith("e/1")
assert data[0]["is_original"] is True
assert data[1]["path"].endswith("x/2")
assert data[1]["is_original"] is False

_check_if_empty_dirs_deleted(shell, inverse_order, sh_path, data)


@parameterized([
("sh", False), ("bash", False), ("dash", False),
("sh", True), ("bash", True), ("dash", True)
])
@with_setup(usual_setup_func, usual_teardown_func)
def test_remove_empty_dirs_with_dupe_dirs(shell, inverse_order):
create_file('xxx', 'deep/a/b/c/d/e/1')
create_file('xxx', 'deep/x/1')

sh_path = os.path.join(TESTDIR_NAME, "result.sh")
header, *data, footer = run_rmlint(
"-S {} -Dj -o sh:{}".format(
"A" if inverse_order else "a",
sh_path
),
)

assert len(data) == 2

if inverse_order:
assert data[0]["path"].endswith("x")
assert data[0]["is_original"] is True
assert data[1]["path"].endswith("e")
assert data[1]["is_original"] is False
else:
assert data[0]["path"].endswith("e")
assert data[0]["is_original"] is True
assert data[1]["path"].endswith("x")
assert data[1]["is_original"] is False

_check_if_empty_dirs_deleted(shell, inverse_order, sh_path, data)

0 comments on commit a70970f

Please sign in to comment.