Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
f9290cf
1
Parent(s): 8ad9001
Remove duplicate tests
Browse files
tests/server/test_server_interactions.py
CHANGED
|
@@ -129,104 +129,6 @@ class TestTools:
|
|
| 129 |
result = await client.call_tool("list_tool", {})
|
| 130 |
assert result[0].text == '[\n "x",\n 2\n]' # type: ignore[attr-defined]
|
| 131 |
|
| 132 |
-
async def test_image(self, tmp_path: Path):
|
| 133 |
-
mcp = FastMCP()
|
| 134 |
-
|
| 135 |
-
@mcp.tool
|
| 136 |
-
def image_tool(path: str) -> Image:
|
| 137 |
-
return Image(path)
|
| 138 |
-
|
| 139 |
-
# Create a test image
|
| 140 |
-
image_path = tmp_path / "test.png"
|
| 141 |
-
image_path.write_bytes(b"fake png data")
|
| 142 |
-
|
| 143 |
-
async with Client(mcp) as client:
|
| 144 |
-
result = await client.call_tool("image_tool", {"path": str(image_path)})
|
| 145 |
-
content = result[0]
|
| 146 |
-
assert isinstance(content, ImageContent)
|
| 147 |
-
assert content.type == "image"
|
| 148 |
-
assert content.mimeType == "image/png"
|
| 149 |
-
# Verify base64 encoding
|
| 150 |
-
decoded = base64.b64decode(content.data)
|
| 151 |
-
assert decoded == b"fake png data"
|
| 152 |
-
|
| 153 |
-
async def test_audio(self, tmp_path: Path):
|
| 154 |
-
mcp = FastMCP()
|
| 155 |
-
|
| 156 |
-
@mcp.tool
|
| 157 |
-
def audio_tool(path: str) -> Audio:
|
| 158 |
-
return Audio(path)
|
| 159 |
-
|
| 160 |
-
# Create a test audio file
|
| 161 |
-
audio_path = tmp_path / "test.wav"
|
| 162 |
-
audio_path.write_bytes(b"fake wav data")
|
| 163 |
-
|
| 164 |
-
async with Client(mcp) as client:
|
| 165 |
-
result = await client.call_tool("audio_tool", {"path": str(audio_path)})
|
| 166 |
-
content = result[0]
|
| 167 |
-
assert isinstance(content, AudioContent)
|
| 168 |
-
assert content.type == "audio"
|
| 169 |
-
assert content.mimeType == "audio/wav"
|
| 170 |
-
# Verify base64 encoding
|
| 171 |
-
decoded = base64.b64decode(content.data)
|
| 172 |
-
assert decoded == b"fake wav data"
|
| 173 |
-
|
| 174 |
-
async def test_tool_mixed_list_with_image(
|
| 175 |
-
self, tool_server: FastMCP, tmp_path: Path
|
| 176 |
-
):
|
| 177 |
-
"""Test that lists containing Image objects and other types are handled
|
| 178 |
-
correctly. Note that the non-MCP content will be grouped together."""
|
| 179 |
-
# Create a test image
|
| 180 |
-
image_path = tmp_path / "test.png"
|
| 181 |
-
image_path.write_bytes(b"test image data")
|
| 182 |
-
|
| 183 |
-
async with Client(tool_server) as client:
|
| 184 |
-
result = await client.call_tool(
|
| 185 |
-
"mixed_list_fn", {"image_path": str(image_path)}
|
| 186 |
-
)
|
| 187 |
-
assert len(result) == 3
|
| 188 |
-
# Check text conversion
|
| 189 |
-
content1 = result[0]
|
| 190 |
-
assert isinstance(content1, TextContent)
|
| 191 |
-
assert json.loads(content1.text) == ["text message", {"key": "value"}]
|
| 192 |
-
# Check image conversion
|
| 193 |
-
content2 = result[1]
|
| 194 |
-
assert isinstance(content2, ImageContent)
|
| 195 |
-
assert content2.mimeType == "image/png"
|
| 196 |
-
assert base64.b64decode(content2.data) == b"test image data"
|
| 197 |
-
# Check direct TextContent
|
| 198 |
-
content3 = result[2]
|
| 199 |
-
assert isinstance(content3, TextContent)
|
| 200 |
-
assert content3.text == "direct content"
|
| 201 |
-
|
| 202 |
-
async def test_tool_mixed_list_with_audio(
|
| 203 |
-
self, tool_server: FastMCP, tmp_path: Path
|
| 204 |
-
):
|
| 205 |
-
"""Test that lists containing Audio objects and other types are handled
|
| 206 |
-
correctly. Note that the non-MCP content will be grouped together."""
|
| 207 |
-
# Create a test audio file
|
| 208 |
-
audio_path = tmp_path / "test.wav"
|
| 209 |
-
audio_path.write_bytes(b"test audio data")
|
| 210 |
-
|
| 211 |
-
async with Client(tool_server) as client:
|
| 212 |
-
result = await client.call_tool(
|
| 213 |
-
"mixed_audio_list_fn", {"audio_path": str(audio_path)}
|
| 214 |
-
)
|
| 215 |
-
assert len(result) == 3
|
| 216 |
-
# Check text conversion
|
| 217 |
-
content1 = result[0]
|
| 218 |
-
assert isinstance(content1, TextContent)
|
| 219 |
-
assert json.loads(content1.text) == ["text message", {"key": "value"}]
|
| 220 |
-
# Check audio conversion
|
| 221 |
-
content2 = result[1]
|
| 222 |
-
assert isinstance(content2, AudioContent)
|
| 223 |
-
assert content2.mimeType == "audio/wav"
|
| 224 |
-
assert base64.b64decode(content2.data) == b"test audio data"
|
| 225 |
-
# Check direct TextContent
|
| 226 |
-
content3 = result[2]
|
| 227 |
-
assert isinstance(content3, TextContent)
|
| 228 |
-
assert content3.text == "direct content"
|
| 229 |
-
|
| 230 |
|
| 231 |
class TestToolTags:
|
| 232 |
def create_server(self, include_tags=None, exclude_tags=None):
|
|
|
|
| 129 |
result = await client.call_tool("list_tool", {})
|
| 130 |
assert result[0].text == '[\n "x",\n 2\n]' # type: ignore[attr-defined]
|
| 131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
class TestToolTags:
|
| 134 |
def create_server(self, include_tags=None, exclude_tags=None):
|