add tests for FastMCP integration and update pre-commit
This commit is contained in:
parent
24c442d5c4
commit
664c2adedc
@ -10,24 +10,24 @@ repos:
|
||||
args: [--pytest-test-first]
|
||||
- id: requirements-txt-fixer
|
||||
- repo: https://github.com/asottile/setup-cfg-fmt
|
||||
rev: v2.8.0
|
||||
rev: v3.2.0
|
||||
hooks:
|
||||
- id: setup-cfg-fmt
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: 6.0.1
|
||||
rev: 7.0.0
|
||||
hooks:
|
||||
- id: isort
|
||||
name: isort (python)
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 22.10.0
|
||||
rev: 25.12.0
|
||||
hooks:
|
||||
- id: black
|
||||
- repo: https://github.com/PyCQA/flake8
|
||||
rev: 7.2.0
|
||||
rev: 7.3.0
|
||||
hooks:
|
||||
- id: flake8
|
||||
args: [--max-line-length=88]
|
||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: v1.15.0
|
||||
rev: v1.19.0
|
||||
hooks:
|
||||
- id: mypy
|
||||
|
||||
@ -18,9 +18,11 @@ dependencies = [
|
||||
[project.optional-dependencies]
|
||||
dev = [
|
||||
"pytest >= 7.0",
|
||||
"pytest-asyncio",
|
||||
"pre-commit"
|
||||
]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
# Tell pytest where to find the package
|
||||
pythonpath = ["src"]
|
||||
pythonpath = ["src", "."]
|
||||
asyncio_mode = "auto"
|
||||
|
||||
52
tests/integration/test_server.py
Normal file
52
tests/integration/test_server.py
Normal file
@ -0,0 +1,52 @@
|
||||
import pytest
|
||||
from fastmcp.client import Client
|
||||
from fastmcp.client.transports import FastMCPTransport
|
||||
|
||||
from main import app as mcp_app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def main_mcp_client():
|
||||
async with Client(transport=mcp_app) as mcp_client:
|
||||
yield mcp_client
|
||||
|
||||
|
||||
async def test_get_blocks(main_mcp_client: Client[FastMCPTransport]):
|
||||
"""Test retrieving available blocks."""
|
||||
blocks = await main_mcp_client.call_tool(name="get_blocks")
|
||||
assert blocks.data is not None
|
||||
# We don't know exactly what blocks are there, but should get a list
|
||||
assert isinstance(blocks.data, list)
|
||||
|
||||
|
||||
async def test_make_and_remove_block(main_mcp_client: Client[FastMCPTransport]):
|
||||
"""Test making a block and then removing it."""
|
||||
block_type = "analog_sig_source_x"
|
||||
|
||||
# helper to check if block exists in the flowgraph
|
||||
async def get_block_names():
|
||||
current_blocks = await main_mcp_client.call_tool(name="get_blocks")
|
||||
return [b["name"] for b in current_blocks.data] # type: ignore
|
||||
|
||||
# 1. Create a block
|
||||
result = await main_mcp_client.call_tool(
|
||||
name="make_block", arguments={"block_name": block_type}
|
||||
)
|
||||
assert result.data is not None
|
||||
# The output is the new block name, likely something like "analog_sig_source_x_0"
|
||||
new_block_name = str(result.data)
|
||||
assert block_type in new_block_name
|
||||
|
||||
# Verify it exists
|
||||
block_names = await get_block_names()
|
||||
assert new_block_name in block_names
|
||||
|
||||
# 2. Remove the block
|
||||
remove_result = await main_mcp_client.call_tool(
|
||||
name="remove_block", arguments={"block_name": new_block_name}
|
||||
)
|
||||
assert remove_result.data is True
|
||||
|
||||
# Verify it's gone
|
||||
block_names = await get_block_names()
|
||||
assert new_block_name not in block_names
|
||||
3
tox.ini
3
tox.ini
@ -3,3 +3,6 @@ ignore = E265,E501,W504
|
||||
|
||||
[isort]
|
||||
profile = black
|
||||
|
||||
[flake8]
|
||||
max-line-length = 120
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user