refactor: move inline imports to module level (#1893)

This commit is contained in:
Max Isbey 2026-01-16 15:54:08 +01:00 • committed by GitHub
commit 5d80f4efc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,10 +6,16 @@
# pyright: reportUnknownMemberType=false
import sys
from pathlib import Path
import pytest
from pydantic import AnyUrl
from pytest_examples import CodeExample, EvalExample, find_examples
from examples.fastmcp.complex_inputs import mcp as complex_inputs_mcp
from examples.fastmcp.desktop import mcp as desktop_mcp
from examples.fastmcp.direct_call_tool_result_return import mcp as direct_call_tool_result_mcp
from examples.fastmcp.simple_echo import mcp as simple_echo_mcp
from mcp.shared.memory import create_connected_server_and_client_session as client_session
from mcp.types import TextContent, TextResourceContents
@ -17,9 +23,7 @@ from mcp.types import TextContent, TextResourceContents
@pytest.mark.anyio
async def test_simple_echo():
"""Test the simple echo server"""
from examples.fastmcp.simple_echo import mcp
async with client_session(mcp._mcp_server) as client:
async with client_session(simple_echo_mcp._mcp_server) as client:
result = await client.call_tool("echo", {"text": "hello"})
assert len(result.content) == 1
content = result.content[0]
@ -30,9 +34,7 @@ async def test_simple_echo():
@pytest.mark.anyio
async def test_complex_inputs():
"""Test the complex inputs server"""
from examples.fastmcp.complex_inputs import mcp
async with client_session(mcp._mcp_server) as client:
async with client_session(complex_inputs_mcp._mcp_server) as client:
tank = {"shrimp": [{"name": "bob"}, {"name": "alice"}]}
result = await client.call_tool("name_shrimp", {"tank": tank, "extra_names": ["charlie"]})
assert len(result.content) == 3
@ -47,9 +49,7 @@ async def test_complex_inputs():
@pytest.mark.anyio
async def test_direct_call_tool_result_return():
"""Test the CallToolResult echo server"""
from examples.fastmcp.direct_call_tool_result_return import mcp
async with client_session(mcp._mcp_server) as client:
async with client_session(direct_call_tool_result_mcp._mcp_server) as client:
result = await client.call_tool("echo", {"text": "hello"})
assert len(result.content) == 1
content = result.content[0]
@ -64,18 +64,12 @@ async def test_direct_call_tool_result_return():
@pytest.mark.anyio
async def test_desktop(monkeypatch: pytest.MonkeyPatch):
"""Test the desktop server"""
from pathlib import Path
from pydantic import AnyUrl
from examples.fastmcp.desktop import mcp
# Mock desktop directory listing
mock_files = [Path("/fake/path/file1.txt"), Path("/fake/path/file2.txt")]
monkeypatch.setattr(Path, "iterdir", lambda self: mock_files) # type: ignore[reportUnknownArgumentType]
monkeypatch.setattr(Path, "home", lambda: Path("/fake/home"))
async with client_session(mcp._mcp_server) as client:
async with client_session(desktop_mcp._mcp_server) as client:
# Test the sum function
result = await client.call_tool("sum", {"a": 1, "b": 2})
assert len(result.content) == 1