1
1
"""Tests for example servers"""
2
+
2
3
# TODO(Marcelo): The `examples` directory needs to be importable as a package.
3
4
# pyright: reportMissingImports=false
4
5
# pyright: reportUnknownVariableType=false
5
6
# pyright: reportUnknownArgumentType=false
6
7
# pyright: reportUnknownMemberType=false
7
-
8
8
import sys
9
+ from pathlib import Path
9
10
10
11
import pytest
12
+ from pydantic import AnyUrl
11
13
from pytest_examples import CodeExample , EvalExample , find_examples
12
14
15
+ from examples .fastmcp .desktop import mcp
13
16
from mcp .shared .memory import create_connected_server_and_client_session as client_session
14
17
from mcp .types import TextContent , TextResourceContents
15
18
@@ -45,13 +48,23 @@ async def test_complex_inputs():
45
48
46
49
47
50
@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 ]):
49
67
"""Test the desktop server"""
50
- from pathlib import Path
51
-
52
- from pydantic import AnyUrl
53
-
54
- from examples .fastmcp .desktop import mcp
55
68
56
69
# Mock desktop directory listing
57
70
mock_files = [Path ("/fake/path/file1.txt" ), Path ("/fake/path/file2.txt" )]
@@ -72,15 +85,7 @@ async def test_desktop(monkeypatch: pytest.MonkeyPatch):
72
85
content = result .contents [0 ]
73
86
assert isinstance (content , TextResourceContents )
74
87
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 )
84
89
85
90
86
91
@pytest .mark .parametrize ("example" , find_examples ("README.md" ), ids = str )
0 commit comments