Skip to content

Commit 49b250e

Browse files
committed
tests/cli(test[privacy]): Cover PrivatePath logging
1 parent 1e84a78 commit 49b250e

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

tests/cli/test_add.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import argparse
66
import logging
77
import os
8+
import pathlib
89
import re
910
import subprocess
1011
import textwrap
@@ -692,6 +693,8 @@ def test_handle_add_command_path_mode(
692693
else:
693694
repo_arg = str(repo_path)
694695

696+
repo_name = override_name or repo_path.name
697+
695698
args = argparse.Namespace(
696699
repo_path=repo_arg,
697700
url=explicit_url,
@@ -713,6 +716,10 @@ def test_handle_add_command_path_mode(
713716

714717
normalized_log = log_output.replace(str(config_file), "<config>")
715718
normalized_log = normalized_log.replace(str(repo_path), "<repo_path>")
719+
normalized_log = normalized_log.replace(
720+
f"Aborted import of '{repo_name}' from {PrivatePath(repo_path)!s}",
721+
f"Aborted import of '{repo_name}' from <repo_path>",
722+
)
716723
normalized_log = re.sub(r"add\.py:\d+", "add.py:<line>", normalized_log)
717724
if preserve_config_path_in_log:
718725
assert str(PrivatePath(config_file)) in log_output
@@ -734,8 +741,6 @@ def test_handle_add_command_path_mode(
734741
if expected_warning is not None:
735742
assert expected_warning in log_output
736743

737-
repo_name = override_name or repo_path.name
738-
739744
if expected_written:
740745
import yaml
741746

@@ -805,6 +810,42 @@ def test_add_repo_dry_run_contracts_config_path(
805810
assert "~/.vcspull.yaml" in caplog.text
806811

807812

813+
def test_handle_add_command_abort_uses_private_path(
814+
tmp_path: pathlib.Path,
815+
monkeypatch: MonkeyPatch,
816+
caplog: t.Any,
817+
) -> None:
818+
"""Aborted add command logs repo path with home collapsed."""
819+
caplog.set_level(logging.INFO)
820+
821+
home = tmp_path / "home"
822+
home.mkdir()
823+
monkeypatch.chdir(home)
824+
# Ensure PrivatePath resolves tilde within the temp home directory.
825+
monkeypatch.setattr(pathlib.Path, "home", lambda: home)
826+
827+
repo_path = home / "study/python/pytest-docker"
828+
repo_path.mkdir(parents=True)
829+
830+
args = argparse.Namespace(
831+
repo_path=str(repo_path),
832+
override_name=None,
833+
url=None,
834+
config=str(home / ".vcspull.yaml"),
835+
workspace_root_path=None,
836+
dry_run=False,
837+
assume_yes=False,
838+
merge_duplicates=True,
839+
)
840+
841+
monkeypatch.setattr("builtins.input", lambda _: "n")
842+
843+
handle_add_command(args)
844+
845+
expected_path = str(PrivatePath(repo_path))
846+
assert f"Aborted import of 'pytest-docker' from {expected_path}" in caplog.text
847+
848+
808849
def test_add_parser_rejects_extra_positional() -> None:
809850
"""Passing both name and URL should raise a parse error in the new parser."""
810851
parser = argparse.ArgumentParser(prog="vcspull")

0 commit comments

Comments
 (0)