Patch SembleIndex.from_path with a fake index and invoke the tool, returning the text.
(
cache: _IndexCache,
tool: str,
args: dict[str, Any],
*,
index_method: str,
index_return: list[SearchResult],
index_chunks: list[Chunk] | None = None,
)
| 20 | |
| 21 | |
| 22 | async def _call_tool( |
| 23 | cache: _IndexCache, |
| 24 | tool: str, |
| 25 | args: dict[str, Any], |
| 26 | *, |
| 27 | index_method: str, |
| 28 | index_return: list[SearchResult], |
| 29 | index_chunks: list[Chunk] | None = None, |
| 30 | ) -> str: |
| 31 | """Patch SembleIndex.from_path with a fake index and invoke the tool, returning the text.""" |
| 32 | fake_index = MagicMock() |
| 33 | getattr(fake_index, index_method).return_value = index_return |
| 34 | if index_chunks is not None: |
| 35 | fake_index.chunks = index_chunks |
| 36 | with patch("semble.mcp.SembleIndex.from_path", return_value=fake_index): |
| 37 | server = create_server(cache) |
| 38 | result = await server.call_tool(tool, args) |
| 39 | return _tool_text(result) |
| 40 | |
| 41 | |
| 42 | @pytest.fixture() |
no test coverage detected