11"""Tests for example servers"""
2+
23# TODO(Marcelo): The `examples` directory needs to be importable as a package.
34# pyright: reportMissingImports=false
45# pyright: reportUnknownVariableType=false
56# pyright: reportUnknownArgumentType=false
67# pyright: reportUnknownMemberType=false
7-
88import sys
9+ from pathlib import Path
910
1011import pytest
12+ from pydantic import AnyUrl
1113from pytest_examples import CodeExample , EvalExample , find_examples
1214
15+ from examples .fastmcp .desktop import mcp
1316from mcp .shared .memory import create_connected_server_and_client_session as client_session
1417from mcp .types import TextContent , TextResourceContents
1518
@@ -45,13 +48,23 @@ async def test_complex_inputs():
4548
4649
4750@pytest .mark .anyio
48- async def test_desktop (monkeypatch : pytest .MonkeyPatch ):
51+ @pytest .mark .parametrize (
52+ "files" ,
53+ [
54+ pytest .param (
55+ ["/fake/path/file1.txt" , "/fake/path/file2.txt" ],
56+ id = "unix" ,
57+ marks = pytest .mark .skipif (sys .platform == "win32" , reason = "Unix-specific test" ),
58+ ),
59+ pytest .param (
60+ ["C:\\ fake\\ path\\ file1.txt" , "C:\\ fake\\ path\\ file2.txt" ],
61+ id = "windows" ,
62+ marks = pytest .mark .skipif (sys .platform != "win32" , reason = "Windows-specific test" ),
63+ ),
64+ ],
65+ )
66+ async def test_desktop (monkeypatch : pytest .MonkeyPatch , files : list [str ]):
4967 """Test the desktop server"""
50- from pathlib import Path
51-
52- from pydantic import AnyUrl
53-
54- from examples .fastmcp .desktop import mcp
5568
5669 # Mock desktop directory listing
5770 mock_files = [Path ("/fake/path/file1.txt" ), Path ("/fake/path/file2.txt" )]
@@ -72,15 +85,7 @@ async def test_desktop(monkeypatch: pytest.MonkeyPatch):
7285 content = result .contents [0 ]
7386 assert isinstance (content , TextResourceContents )
7487 assert isinstance (content .text , str )
75- if sys .platform == "win32" :
76- file_1 = "/fake/path/file1.txt" .replace ("/" , "\\ \\ " ) # might be a bug
77- file_2 = "/fake/path/file2.txt" .replace ("/" , "\\ \\ " ) # might be a bug
78- assert file_1 in content .text
79- assert file_2 in content .text
80- # might be a bug, but the test is passing
81- else :
82- assert "/fake/path/file1.txt" in content .text
83- assert "/fake/path/file2.txt" in content .text
88+ assert all (file in content .text for file in files )
8489
8590
8691@pytest .mark .parametrize ("example" , find_examples ("README.md" ), ids = str )
0 commit comments