Migrate from FastMCP 2.14.5 to 3.1.0 with complete architectural overhaul. Adopt src-layout packaging, lazy config functions to eliminate .env race condition, and decorator-based tool registration. Consolidate 14 tool modules into 8 focused modules (33 tools total). Add 9 new schematic tools via kicad-sch-api for creating and manipulating .kicad_sch files. Drop pandas dependency (BOM uses stdlib csv). Remove ~17k lines of stubs, over-engineering, and dead code. All checks pass: ruff clean, mypy 0 errors, 17/17 tests green.
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
"""Tests for schematic tools (kicad-sch-api integration)."""
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_create_schematic(tmp_output_dir):
|
|
"""create_schematic should produce a .kicad_sch file."""
|
|
from mckicad.tools.schematic import create_schematic
|
|
|
|
output_path = os.path.join(tmp_output_dir, "test.kicad_sch")
|
|
result = create_schematic(name="test_circuit", output_path=output_path)
|
|
assert result["success"] is True
|
|
assert os.path.exists(output_path)
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_create_schematic_invalid_path():
|
|
"""create_schematic should fail gracefully for invalid paths."""
|
|
from mckicad.tools.schematic import create_schematic
|
|
|
|
result = create_schematic(name="x", output_path="/nonexistent/dir/test.kicad_sch")
|
|
assert result["success"] is False
|
|
assert "error" in result
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_search_components():
|
|
"""search_components should return results for common queries."""
|
|
from mckicad.tools.schematic import search_components
|
|
|
|
result = search_components(query="resistor")
|
|
# Should succeed even if no libs installed (returns empty results)
|
|
assert "success" in result
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_list_components_empty_schematic(tmp_output_dir):
|
|
"""list_components on new empty schematic should return empty list."""
|
|
from mckicad.tools.schematic import create_schematic, list_components
|
|
|
|
path = os.path.join(tmp_output_dir, "empty.kicad_sch")
|
|
create_schematic(name="empty", output_path=path)
|
|
result = list_components(schematic_path=path)
|
|
if result["success"]:
|
|
assert result.get("count", 0) == 0
|