Skip to content

Commit 0f88ac9

Browse files
committed
tests/cli(test[add]): cover tilde workspace behaviour
why: Guard against regressions when runs from inside the workspace with and without . what: - add tests confirming tilde-labelled workspaces and './' upgrades
1 parent d715890 commit 0f88ac9

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

tests/cli/test_add.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,3 +932,106 @@ def test_handle_add_command_workspace_label_from_workspace_root(
932932
config_data = yaml.safe_load(fh)
933933

934934
assert expected_label in config_data
935+
936+
937+
@pytest.mark.parametrize("merge_duplicates", [True, False])
938+
def test_handle_add_command_workspace_label_variants(
939+
merge_duplicates: bool,
940+
tmp_path: pathlib.Path,
941+
monkeypatch: MonkeyPatch,
942+
caplog: t.Any,
943+
) -> None:
944+
"""Path-first adds should keep tilde workspaces regardless of merge flag."""
945+
caplog.set_level(logging.INFO)
946+
947+
monkeypatch.setenv("HOME", str(tmp_path))
948+
949+
workspace_root = tmp_path / "study/python"
950+
repo_path = workspace_root / "pytest-docker"
951+
init_git_repo(repo_path, remote_url="https://github.com/avast/pytest-docker")
952+
953+
monkeypatch.chdir(workspace_root)
954+
955+
config_file = tmp_path / ".vcspull.yaml"
956+
957+
args = argparse.Namespace(
958+
repo_path=str(repo_path),
959+
url=None,
960+
override_name=None,
961+
config=str(config_file),
962+
workspace_root_path=None,
963+
dry_run=False,
964+
assume_yes=True,
965+
merge_duplicates=merge_duplicates,
966+
)
967+
968+
handle_add_command(args)
969+
970+
expected_label = "~/study/python/"
971+
972+
assert expected_label in caplog.text
973+
974+
import yaml
975+
976+
with config_file.open(encoding="utf-8") as fh:
977+
config_data = yaml.safe_load(fh) or {}
978+
979+
assert expected_label in config_data
980+
assert "./" not in config_data
981+
982+
983+
def test_handle_add_command_upgrades_dot_workspace_section(
984+
tmp_path: pathlib.Path,
985+
monkeypatch: MonkeyPatch,
986+
caplog: t.Any,
987+
) -> None:
988+
"""Existing './' sections should be relabeled to their tilde equivalent."""
989+
caplog.set_level(logging.INFO)
990+
991+
monkeypatch.setenv("HOME", str(tmp_path))
992+
993+
workspace_root = tmp_path / "study/python"
994+
repo_path = workspace_root / "pytest-docker"
995+
init_git_repo(repo_path, remote_url="https://github.com/avast/pytest-docker")
996+
997+
monkeypatch.chdir(workspace_root)
998+
999+
config_file = tmp_path / ".vcspull.yaml"
1000+
import yaml
1001+
1002+
config_file.write_text(
1003+
yaml.dump(
1004+
{
1005+
"./": {
1006+
"existing": {
1007+
"repo": "git+https://github.com/example/existing.git",
1008+
},
1009+
},
1010+
},
1011+
),
1012+
encoding="utf-8",
1013+
)
1014+
1015+
args = argparse.Namespace(
1016+
repo_path=str(repo_path),
1017+
url=None,
1018+
override_name=None,
1019+
config=str(config_file),
1020+
workspace_root_path=None,
1021+
dry_run=False,
1022+
assume_yes=True,
1023+
merge_duplicates=True,
1024+
)
1025+
1026+
handle_add_command(args)
1027+
1028+
expected_label = "~/study/python/"
1029+
assert expected_label in caplog.text
1030+
1031+
with config_file.open(encoding="utf-8") as fh:
1032+
config_data = yaml.safe_load(fh) or {}
1033+
1034+
assert expected_label in config_data
1035+
assert "./" not in config_data
1036+
assert "existing" in config_data[expected_label]
1037+
assert "pytest-docker" in config_data[expected_label]

0 commit comments

Comments
 (0)