|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Test runner for KiCad MCP project. |
| 4 | +""" |
| 5 | +import subprocess |
| 6 | +import sys |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | + |
| 10 | +def run_command(cmd: list[str], description: str) -> int: |
| 11 | + """Run a command and return the exit code.""" |
| 12 | + print(f"\n🔍 {description}") |
| 13 | + print(f"Running: {' '.join(cmd)}") |
| 14 | + |
| 15 | + try: |
| 16 | + result = subprocess.run(cmd, check=False) |
| 17 | + if result.returncode == 0: |
| 18 | + print(f"✅ {description} passed") |
| 19 | + else: |
| 20 | + print(f"❌ {description} failed with exit code {result.returncode}") |
| 21 | + return result.returncode |
| 22 | + except FileNotFoundError: |
| 23 | + print(f"❌ Command not found: {cmd[0]}") |
| 24 | + return 1 |
| 25 | + |
| 26 | + |
| 27 | +def main(): |
| 28 | + """Run all tests and checks.""" |
| 29 | + project_root = Path(__file__).parent |
| 30 | + |
| 31 | + # Change to project directory |
| 32 | + import os |
| 33 | + |
| 34 | + os.chdir(project_root) |
| 35 | + |
| 36 | + exit_code = 0 |
| 37 | + |
| 38 | + # Run linting |
| 39 | + exit_code |= run_command(["uv", "run", "ruff", "check", "kicad_mcp/", "tests/"], "Lint check") |
| 40 | + |
| 41 | + # Run formatting check |
| 42 | + exit_code |= run_command( |
| 43 | + ["uv", "run", "ruff", "format", "--check", "kicad_mcp/", "tests/"], "Format check" |
| 44 | + ) |
| 45 | + |
| 46 | + # Run type checking |
| 47 | + exit_code |= run_command(["uv", "run", "mypy", "kicad_mcp/"], "Type check") |
| 48 | + |
| 49 | + # Run tests |
| 50 | + exit_code |= run_command(["uv", "run", "python", "-m", "pytest", "tests/", "-v"], "Unit tests") |
| 51 | + |
| 52 | + if exit_code == 0: |
| 53 | + print("\n🎉 All checks passed!") |
| 54 | + else: |
| 55 | + print(f"\n💥 Some checks failed (exit code: {exit_code})") |
| 56 | + |
| 57 | + return exit_code |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + sys.exit(main()) |
0 commit comments