You've already forked OrthoRoute
mirror of
https://github.com/bbenchoff/OrthoRoute.git
synced 2026-08-23 06:27:01 +00:00
2.3 KiB
2.3 KiB
name, description
| name | description |
|---|---|
| add-unit-test | Scaffold a pytest unit test for a given OrthoRoute function or class |
Add Unit Test
Scaffold a pytest unit test for the specified OrthoRoute symbol.
Inputs
- symbol: The fully-qualified name of the function or class to test (e.g.
orthoroute.domain.models.board.Board,orthoroute.algorithms.manhattan.real_global_grid.GlobalGrid.gid_roundtrip) - test_type (optional):
unit(default) orintegration
Instructions
- Locate
${symbol}in the codebase and read its implementation. - Identify:
- All inputs/outputs and their types
- Edge cases (empty board, single pad, zero nets, OOM path, etc.)
- Any existing inline "test" scripts (
if __name__ == "__main__") that document expected behavior — convert those into proper pytest assertions
- Create the test file at
tests/<mirrored_module_path>/test_<module_name>.py, creating the directory and an__init__.pyif they do not exist. - Write tests following these conventions:
- One
test_function per behavior, not per method - Use
pytest.fixturefor shared setup (Board instances, config, grid) - Use
@pytest.mark.parametrizefor input/output tables - Prefer real domain objects over mocks; mock only I/O boundaries (KiCad IPC, file system, GPU)
- Assert specific values, not just "no exception raised"
- One
- Add a
# TODO:comment for any behavior that needs deeper integration (e.g., full routing pipeline) — do not expand scope. - Run
pytest tests/<new_file> -vand confirm all tests pass.
Example
Input: symbol = "orthoroute.domain.models.board.Board"
Output location: tests/domain/models/test_board.py
import pytest
from orthoroute.domain.models.board import Board
@pytest.fixture
def empty_board():
return Board(layers=[], nets=[], pads=[])
def test_board_has_no_nets_by_default(empty_board):
assert empty_board.nets == []
def test_board_layer_count(empty_board):
assert empty_board.layer_count == 0
@pytest.mark.parametrize("layer_names,expected", [
(["F.Cu", "B.Cu"], 2),
(["F.Cu", "In1.Cu", "In2.Cu", "B.Cu"], 4),
])
def test_board_layer_count_parametrized(layer_names, expected):
board = Board(layers=layer_names, nets=[], pads=[])
assert board.layer_count == expected