Test the desktop server
(tmp_path: Path, monkeypatch: pytest.MonkeyPatch)
| 65 | |
| 66 | @pytest.mark.anyio |
| 67 | async def test_desktop(tmp_path: Path, monkeypatch: pytest.MonkeyPatch): |
| 68 | """Test the desktop server""" |
| 69 | # Build a real Desktop directory under tmp_path rather than patching |
| 70 | # Path.iterdir — a class-level patch breaks jsonschema_specifications' |
| 71 | # import-time schema discovery when this test happens to be the first |
| 72 | # tool call in an xdist worker. |
| 73 | desktop = tmp_path / "Desktop" |
| 74 | desktop.mkdir() |
| 75 | (desktop / "file1.txt").touch() |
| 76 | (desktop / "file2.txt").touch() |
| 77 | monkeypatch.setattr(Path, "home", lambda: tmp_path) |
| 78 | |
| 79 | from examples.mcpserver.desktop import mcp |
| 80 | |
| 81 | async with Client(mcp) as client: |
| 82 | # Test the sum function |
| 83 | result = await client.call_tool("sum", {"a": 1, "b": 2}) |
| 84 | assert result == snapshot(CallToolResult(content=[TextContent(text="3")], structured_content={"result": 3})) |
| 85 | |
| 86 | # Test the desktop resource |
| 87 | result = await client.read_resource("dir://desktop") |
| 88 | assert len(result.contents) == 1 |
| 89 | content = result.contents[0] |
| 90 | assert isinstance(content, TextResourceContents) |
| 91 | assert isinstance(content.text, str) |
| 92 | assert "file1.txt" in content.text |
| 93 | assert "file2.txt" in content.text |
| 94 | |
| 95 | |
| 96 | # TODO(v2): Change back to README.md when v2 is released |
nothing calls this directly
no test coverage detected