"""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