1
0
Fork 0
mirror of synced 2024-12-22 06:31:07 -05:00
yadm/test/test_unit_remove_stale_links.py

40 lines
984 B
Python
Raw Normal View History

2019-09-30 09:44:41 -04:00
"""Unit tests: remove_stale_links"""
2019-09-30 09:44:41 -04:00
import os
2023-07-10 10:14:33 -04:00
2019-09-30 09:44:41 -04:00
import pytest
2023-07-10 15:43:17 -04:00
@pytest.mark.parametrize("linked", [True, False])
@pytest.mark.parametrize("kind", ["file", "symlink"])
2019-09-30 09:44:41 -04:00
def test_remove_stale_links(runner, yadm, tmpdir, kind, linked):
"""Test remove_stale_links()"""
2023-07-10 15:43:17 -04:00
source_file = tmpdir.join("source_file")
source_file.write("source file", ensure=True)
link = tmpdir.join("link")
2019-09-30 09:44:41 -04:00
2023-07-10 15:43:17 -04:00
if kind == "file":
link.write("link file", ensure=True)
2019-09-30 09:44:41 -04:00
else:
2023-07-10 15:43:17 -04:00
os.system(f"ln -s {source_file} {link}")
2019-09-30 09:44:41 -04:00
2023-07-10 15:43:17 -04:00
alt_linked = ""
2019-09-30 09:44:41 -04:00
if linked:
alt_linked = source_file
script = f"""
YADM_TEST=1 source {yadm}
possible_alts=({link})
alt_linked=({alt_linked})
function rm() {{ echo rm "$@"; }}
remove_stale_links
"""
2023-07-10 15:43:17 -04:00
run = runner(command=["bash"], inp=script)
assert run.err == ""
if kind == "symlink" and not linked:
assert f"rm -f {link}" in run.out
2019-09-30 09:44:41 -04:00
else:
2023-07-10 15:43:17 -04:00
assert run.out == ""