MCPcopy
hub / github.com/MinishLab/semble / test_cli_find_related

Function test_cli_find_related

tests/test_cli.py:63–89  ·  view source on GitHub ↗

_cli_main find-related prints results, empty states, and missing-chunk errors.

(
    scenario: str,
    expected_stdout: list[str],
    expected_stderr: str | None,
    expected_exit_code: int | None,
    monkeypatch: pytest.MonkeyPatch,
    capsys: pytest.CaptureFixture[str],
)

Source from the content-addressed store, hash-verified

61 ],
62)
63def test_cli_find_related(
64 scenario: str,
65 expected_stdout: list[str],
66 expected_stderr: str | None,
67 expected_exit_code: int | None,
68 monkeypatch: pytest.MonkeyPatch,
69 capsys: pytest.CaptureFixture[str],
70) -> None:
71 """_cli_main find-related prints results, empty states, and missing-chunk errors."""
72 chunk = make_chunk("class Bar: pass", "src/bar.py")
73 fake_index = MagicMock()
74 fake_index.chunks = [] if scenario == "unknown_chunk" else [chunk]
75 fake_index.find_related.return_value = [SearchResult(chunk=chunk, score=0.8)] if scenario == "with_results" else []
76 file_path = "unknown.py" if scenario == "unknown_chunk" else "src/bar.py"
77 monkeypatch.setattr(sys, "argv", ["semble", "find-related", file_path, "1", "/some/path"])
78 with patch("semble.cli.SembleIndex.from_path", return_value=fake_index):
79 if expected_exit_code is None:
80 _cli_main()
81 else:
82 with pytest.raises(SystemExit) as exc_info:
83 _cli_main()
84 assert exc_info.value.code == expected_exit_code
85 captured = capsys.readouterr()
86 for fragment in expected_stdout:
87 assert fragment in captured.out
88 if expected_stderr:
89 assert expected_stderr in captured.err
90
91
92def test_main_dispatches_to_cli(

Callers

nothing calls this directly

Calls 3

make_chunkFunction · 0.90
SearchResultClass · 0.90
_cli_mainFunction · 0.90

Tested by

no test coverage detected