mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-24 06:24:18 +02:00
Address maintainer review: reload support, type annotation, test imports
This commit is contained in:
parent
52144ce20b
commit
9d635bc026
3 changed files with 40 additions and 40 deletions
|
|
@ -1,13 +1,18 @@
|
|||
import inspect
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from fastmcp.cli.cli import inspector, run
|
||||
from fastmcp.cli.run import (
|
||||
create_mcp_config_server,
|
||||
is_url,
|
||||
run_module_command,
|
||||
)
|
||||
from fastmcp.client.client import Client
|
||||
from fastmcp.client.transports import FastMCPTransport
|
||||
|
|
@ -702,10 +707,6 @@ class TestRunModuleCommand:
|
|||
|
||||
def test_runs_python_m_module(self):
|
||||
"""Test that run_module_command invokes python -m <module>."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from fastmcp.cli.run import run_module_command
|
||||
|
||||
mock_result = MagicMock()
|
||||
mock_result.returncode = 0
|
||||
|
||||
|
|
@ -725,10 +726,6 @@ class TestRunModuleCommand:
|
|||
|
||||
def test_forwards_extra_args(self):
|
||||
"""Test that extra arguments are forwarded after the module name."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from fastmcp.cli.run import run_module_command
|
||||
|
||||
mock_result = MagicMock()
|
||||
mock_result.returncode = 0
|
||||
|
||||
|
|
@ -746,10 +743,6 @@ class TestRunModuleCommand:
|
|||
|
||||
def test_uses_env_command_builder(self):
|
||||
"""Test that env_command_builder wraps the command."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from fastmcp.cli.run import run_module_command
|
||||
|
||||
mock_result = MagicMock()
|
||||
mock_result.returncode = 0
|
||||
|
||||
|
|
@ -774,11 +767,6 @@ class TestRunModuleCommand:
|
|||
|
||||
def test_exits_with_subprocess_error_code(self):
|
||||
"""Test that non-zero exit codes from the module are propagated."""
|
||||
import subprocess
|
||||
from unittest.mock import patch
|
||||
|
||||
from fastmcp.cli.run import run_module_command
|
||||
|
||||
with (
|
||||
patch(
|
||||
"fastmcp.cli.run.subprocess.run",
|
||||
|
|
@ -792,11 +780,6 @@ class TestRunModuleCommand:
|
|||
|
||||
def test_no_env_builder_runs_plain_python(self):
|
||||
"""Test that without env_command_builder, plain python is used."""
|
||||
import sys
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from fastmcp.cli.run import run_module_command
|
||||
|
||||
mock_result = MagicMock()
|
||||
mock_result.returncode = 0
|
||||
|
||||
|
|
@ -819,8 +802,6 @@ class TestRunModuleMode:
|
|||
|
||||
async def test_run_module_mode_requires_server_spec(self):
|
||||
"""Test that module mode exits with error when server_spec is None."""
|
||||
from fastmcp.cli.cli import run
|
||||
|
||||
with pytest.raises(SystemExit) as exc_info:
|
||||
await run(None, module=True)
|
||||
|
||||
|
|
@ -828,10 +809,6 @@ class TestRunModuleMode:
|
|||
|
||||
async def test_run_module_mode_warns_ignored_options(self, caplog):
|
||||
"""Test that ignored options produce a warning in module mode."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from fastmcp.cli.cli import run
|
||||
|
||||
mock_result = MagicMock()
|
||||
mock_result.returncode = 0
|
||||
|
||||
|
|
@ -846,17 +823,12 @@ class TestRunModuleMode:
|
|||
transport="sse",
|
||||
host="0.0.0.0",
|
||||
port=8080,
|
||||
reload=True,
|
||||
)
|
||||
|
||||
assert any("ignored in module mode" in r.message for r in caplog.records)
|
||||
|
||||
async def test_run_module_mode_delegates_to_run_module_command(self):
|
||||
"""Test that module mode calls run_module_command with correct args."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from fastmcp.cli.cli import run
|
||||
|
||||
mock_result = MagicMock()
|
||||
mock_result.returncode = 0
|
||||
|
||||
|
|
@ -872,16 +844,26 @@ class TestRunModuleMode:
|
|||
assert "-m" in cmd
|
||||
assert "my_module" in cmd
|
||||
|
||||
async def test_run_module_mode_with_reload(self):
|
||||
"""Test that --reload in module mode delegates to run_with_reload."""
|
||||
with patch(
|
||||
"fastmcp.cli.run.run_with_reload", new_callable=AsyncMock
|
||||
) as mock_reload:
|
||||
await run("my_module", module=True, reload=True, skip_env=True)
|
||||
|
||||
mock_reload.assert_called_once()
|
||||
cmd = mock_reload.call_args[0][0]
|
||||
assert "fastmcp" in cmd
|
||||
assert "--module" in cmd
|
||||
assert "--no-reload" in cmd
|
||||
assert "my_module" in cmd
|
||||
|
||||
|
||||
class TestInspectorModuleMode:
|
||||
"""Test the inspector command's module-mode handling."""
|
||||
|
||||
async def test_inspector_module_mode_skips_load_server(self):
|
||||
"""Test that inspector with module=True skips load_server() and forwards --module."""
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from fastmcp.cli.cli import inspector
|
||||
|
||||
mock_config = MagicMock()
|
||||
mock_config.deployment.port = 8080
|
||||
mock_config.environment.build_command = lambda cmd: cmd
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue