fastmcp/tests/cli/test_tasks.py
Jeremiah Lowin 049bd22827
Replace type: ignore[attr-defined] with isinstance assertions in tests (#2665)
* Replace type: ignore[attr-defined] with isinstance assertions in tests

* Fix isinstance assertions in failing tests

- Fix enum test to check for ResponseEnum instead of str
- Fix binary resource test to check for BlobResourceContents instead of TextResourceContents
- Fix Root type tests to check attributes directly instead of isinstance checks

* Fix type errors without using type: ignore

- Remove execution methods from TransformingProvider (only handles transformations)
- Add execution methods to base Provider class with default implementations
- Fix type narrowing in tests using cast() instead of type: ignore
- Fix PromptResult type handling in prompt render tests
- Fix type narrowing in middleware test for arguments and structured_content
2025-12-21 16:37:20 -05:00

51 lines
1.8 KiB
Python

"""Tests for the fastmcp tasks CLI."""
import pytest
from fastmcp.cli.tasks import check_distributed_backend, tasks_app
from fastmcp.utilities.tests import temporary_settings
class TestCheckDistributedBackend:
"""Test the distributed backend checker function."""
def test_succeeds_with_redis_url(self):
"""Test that it succeeds with Redis URL."""
with temporary_settings(docket__url="redis://localhost:6379/0"):
check_distributed_backend()
def test_exits_with_helpful_error_for_memory_url(self):
"""Test that it exits with helpful error for memory:// URLs."""
with temporary_settings(docket__url="memory://test-123"):
with pytest.raises(SystemExit) as exc_info:
check_distributed_backend()
assert isinstance(exc_info.value, SystemExit)
assert exc_info.value.code == 1
class TestWorkerCommand:
"""Test the worker command."""
def test_worker_command_parsing(self):
"""Test that worker command parses arguments correctly."""
command, bound, _ = tasks_app.parse_args(["worker", "server.py"])
assert callable(command)
assert command.__name__ == "worker" # type: ignore[attr-defined]
assert bound.arguments["server_spec"] == "server.py"
class TestTasksAppIntegration:
"""Test the tasks app integration."""
def test_tasks_app_exists(self):
"""Test that the tasks app is properly configured."""
assert "tasks" in tasks_app.name
assert "Docket" in tasks_app.help
def test_tasks_app_has_commands(self):
"""Test that all expected commands are registered."""
# Just verify the app exists and has the right metadata
# Detailed command testing is done in individual test classes
assert "tasks" in tasks_app.name
assert tasks_app.help