From 5de932e2b3de837619a202a561756cffa5722f16 Mon Sep 17 00:00:00 2001 From: Eugene Mikhantyev Date: Sun, 12 Apr 2026 11:22:39 +0100 Subject: [PATCH] refactor: consolidate python/tests/ into tests/ directory Move all Python test files from python/tests/ to the top-level tests/ directory to match the project's CONTRIBUTING.md guidelines. Update sys.path inserts and template path references to reflect the new location. Co-Authored-By: Claude Sonnet 4.6 --- pytest.ini | 2 +- python/tests/__init__.py | 0 {python/tests => tests}/conftest.py | 0 .../test_delete_schematic_component.py | 4 ++-- {python/tests => tests}/test_freerouting.py | 0 .../test_move_with_wire_preservation.py | 22 +++++++++---------- .../test_schematic_analysis.py | 4 ++-- .../test_schematic_component_fields.py | 5 ++--- .../tests => tests}/test_schematic_tools.py | 2 +- .../tests => tests}/test_wire_connectivity.py | 2 +- .../test_wire_junction_changes.py | 2 +- 11 files changed, 21 insertions(+), 22 deletions(-) delete mode 100644 python/tests/__init__.py rename {python/tests => tests}/conftest.py (100%) rename {python/tests => tests}/test_delete_schematic_component.py (98%) rename {python/tests => tests}/test_freerouting.py (100%) rename {python/tests => tests}/test_move_with_wire_preservation.py (99%) rename {python/tests => tests}/test_schematic_analysis.py (99%) rename {python/tests => tests}/test_schematic_component_fields.py (98%) rename {python/tests => tests}/test_schematic_tools.py (99%) rename {python/tests => tests}/test_wire_connectivity.py (99%) rename {python/tests => tests}/test_wire_junction_changes.py (99%) diff --git a/pytest.ini b/pytest.ini index 63d8b3b..9424546 100644 --- a/pytest.ini +++ b/pytest.ini @@ -7,7 +7,7 @@ python_classes = Test* python_functions = test_* # Test paths -testpaths = tests python/tests +testpaths = tests # Minimum Python version minversion = 6.0 diff --git a/python/tests/__init__.py b/python/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/python/tests/conftest.py b/tests/conftest.py similarity index 100% rename from python/tests/conftest.py rename to tests/conftest.py diff --git a/python/tests/test_delete_schematic_component.py b/tests/test_delete_schematic_component.py similarity index 98% rename from python/tests/test_delete_schematic_component.py rename to tests/test_delete_schematic_component.py index 7fa7265..26f62fb 100644 --- a/python/tests/test_delete_schematic_component.py +++ b/tests/test_delete_schematic_component.py @@ -14,9 +14,9 @@ from typing import Any import pytest -sys.path.insert(0, str(Path(__file__).parent.parent)) +sys.path.insert(0, str(Path(__file__).parent.parent / "python")) -TEMPLATE_SCH = Path(__file__).parent.parent / "templates" / "empty.kicad_sch" +TEMPLATE_SCH = Path(__file__).parent.parent / "python" / "templates" / "empty.kicad_sch" # Inline format (single line) – matches what tests previously used PLACED_RESISTOR_INLINE = """\ diff --git a/python/tests/test_freerouting.py b/tests/test_freerouting.py similarity index 100% rename from python/tests/test_freerouting.py rename to tests/test_freerouting.py diff --git a/python/tests/test_move_with_wire_preservation.py b/tests/test_move_with_wire_preservation.py similarity index 99% rename from python/tests/test_move_with_wire_preservation.py rename to tests/test_move_with_wire_preservation.py index 0952d41..7429a6b 100644 --- a/python/tests/test_move_with_wire_preservation.py +++ b/tests/test_move_with_wire_preservation.py @@ -17,11 +17,11 @@ import sexpdata from sexpdata import Symbol # Make python/ importable -sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "python")) from commands.wire_dragger import EPS, WireDragger, _coords_match, _rotate -TEMPLATE_PATH = Path(__file__).resolve().parent.parent / "templates" / "empty.kicad_sch" +TEMPLATE_PATH = Path(__file__).resolve().parent.parent / "python" / "templates" / "empty.kicad_sch" # --------------------------------------------------------------------------- @@ -517,7 +517,7 @@ class TestMoveWithWirePreservation: sch = self._make_schematic() self._add_resistor(sch, "R1", 100, 100) # Call handler directly - sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "python")) from kicad_interface import KiCADInterface iface = KiCADInterface() @@ -541,7 +541,7 @@ class TestMoveWithWirePreservation: self._add_resistor(sch, "R1", 100, 100) self._add_wire(sch, 100, 103.81, 100, 120) # wire from pin 1 upward - sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "python")) from kicad_interface import KiCADInterface iface = KiCADInterface() @@ -572,7 +572,7 @@ class TestMoveWithWirePreservation: self._add_resistor(sch, "R1", 100, 100) self._add_wire(sch, 50, 50, 60, 50) # unrelated wire - sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "python")) from kicad_interface import KiCADInterface iface = KiCADInterface() @@ -596,7 +596,7 @@ class TestMoveWithWirePreservation: # Wire from pin 1 to pin 2 of same component (intra-component wire) self._add_wire(sch, 100, 103.81, 100, 96.19) - sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "python")) from kicad_interface import KiCADInterface iface = KiCADInterface() @@ -621,7 +621,7 @@ class TestMoveWithWirePreservation: self._add_resistor(sch, "R1", 100, 100) self._add_wire(sch, 100, 103.81, 100, 120) - sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "python")) from kicad_interface import KiCADInterface iface = KiCADInterface() @@ -648,7 +648,7 @@ class TestMoveWithWirePreservation: def test_missing_component_returns_error(self) -> None: sch = self._make_schematic() - sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "python")) from kicad_interface import KiCADInterface iface = KiCADInterface() @@ -907,7 +907,7 @@ class TestTouchingPinIntegration: self._add_resistor(sch, "R1", 100, 100) self._add_resistor(sch, "R2", 100, 92.38) - sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "python")) from kicad_interface import KiCADInterface iface = KiCADInterface() @@ -958,7 +958,7 @@ class TestTouchingPinIntegration: self._add_resistor(sch, "R1", 100, 100) self._add_resistor(sch, "R2", 150, 150) # far away - sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "python")) from kicad_interface import KiCADInterface iface = KiCADInterface() @@ -995,7 +995,7 @@ class TestTouchingPinIntegration: idx = content.rfind(")") sch.write_text(content[:idx] + "\n" + wire_sexp + "\n)", encoding="utf-8") - sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "python")) from kicad_interface import KiCADInterface iface = KiCADInterface() diff --git a/python/tests/test_schematic_analysis.py b/tests/test_schematic_analysis.py similarity index 99% rename from python/tests/test_schematic_analysis.py rename to tests/test_schematic_analysis.py index 333058b..d7efab3 100644 --- a/python/tests/test_schematic_analysis.py +++ b/tests/test_schematic_analysis.py @@ -17,7 +17,7 @@ import sexpdata from sexpdata import Symbol # Ensure the python/ package is importable -sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "python")) from commands.schematic_analysis import ( _aabb_overlap, @@ -43,7 +43,7 @@ from commands.schematic_analysis import ( # Helpers # --------------------------------------------------------------------------- -TEMPLATE_PATH = Path(__file__).resolve().parent.parent / "templates" / "empty.kicad_sch" +TEMPLATE_PATH = Path(__file__).resolve().parent.parent / "python" / "templates" / "empty.kicad_sch" def _make_temp_schematic(extra_sexp: str = "") -> Path: diff --git a/python/tests/test_schematic_component_fields.py b/tests/test_schematic_component_fields.py similarity index 98% rename from python/tests/test_schematic_component_fields.py rename to tests/test_schematic_component_fields.py index 96d5d84..714a4e6 100644 --- a/python/tests/test_schematic_component_fields.py +++ b/tests/test_schematic_component_fields.py @@ -12,15 +12,14 @@ from typing import Any import pytest # Ensure python/ directory is on path so kicad_interface can be imported -sys.path.insert(0, str(Path(__file__).parent.parent)) -sys.path.insert(0, str(Path(__file__).parent.parent.parent / "python")) +sys.path.insert(0, str(Path(__file__).parent.parent / "python")) # --------------------------------------------------------------------------- # Helpers shared across tests # --------------------------------------------------------------------------- -TEMPLATE_SCH = Path(__file__).parent.parent / "templates" / "empty.kicad_sch" +TEMPLATE_SCH = Path(__file__).parent.parent / "python" / "templates" / "empty.kicad_sch" # Minimal placed-symbol block we can embed into a schematic for testing PLACED_RESISTOR_BLOCK = """\ diff --git a/python/tests/test_schematic_tools.py b/tests/test_schematic_tools.py similarity index 99% rename from python/tests/test_schematic_tools.py rename to tests/test_schematic_tools.py index ef89753..d8e30d9 100644 --- a/python/tests/test_schematic_tools.py +++ b/tests/test_schematic_tools.py @@ -22,7 +22,7 @@ import sexpdata # Helpers # --------------------------------------------------------------------------- -TEMPLATES_DIR = Path(__file__).parent.parent / "templates" +TEMPLATES_DIR = Path(__file__).parent.parent / "python" / "templates" EMPTY_SCH = TEMPLATES_DIR / "empty.kicad_sch" # Minimal schematic content used by integration tests diff --git a/python/tests/test_wire_connectivity.py b/tests/test_wire_connectivity.py similarity index 99% rename from python/tests/test_wire_connectivity.py rename to tests/test_wire_connectivity.py index 06bb41a..9c013e7 100644 --- a/python/tests/test_wire_connectivity.py +++ b/tests/test_wire_connectivity.py @@ -17,7 +17,7 @@ from unittest.mock import MagicMock, patch import pytest # Ensure the python package root is importable -sys.path.insert(0, str(Path(__file__).parent.parent)) +sys.path.insert(0, str(Path(__file__).parent.parent / "python")) # --------------------------------------------------------------------------- # Module under test diff --git a/python/tests/test_wire_junction_changes.py b/tests/test_wire_junction_changes.py similarity index 99% rename from python/tests/test_wire_junction_changes.py rename to tests/test_wire_junction_changes.py index 063a4fd..56d6f08 100644 --- a/python/tests/test_wire_junction_changes.py +++ b/tests/test_wire_junction_changes.py @@ -18,7 +18,7 @@ import sexpdata from sexpdata import Symbol # Add python dir to path -PYTHON_DIR = Path(__file__).parent.parent +PYTHON_DIR = Path(__file__).parent.parent / "python" sys.path.insert(0, str(PYTHON_DIR)) TEMPLATES_DIR = PYTHON_DIR / "templates"