lots more refactoring

This commit is contained in:
Jan Petykiewicz 2026-03-30 19:51:37 -07:00
commit bc218a416b
43 changed files with 1433 additions and 1694 deletions

View file

@ -1,9 +1,11 @@
import importlib
import pytest
from shapely.geometry import box
from inire import (
CongestionOptions,
DiagnosticsOptions,
LockedRoute,
NetSpec,
ObjectiveWeights,
Port,
@ -16,6 +18,26 @@ from inire import (
from inire.geometry.components import Straight
def test_root_module_exports_only_stable_surface() -> None:
import inire
assert not hasattr(inire, "RoutingWorld")
assert not hasattr(inire, "AStarContext")
assert not hasattr(inire, "PathFinder")
assert not hasattr(inire, "CostEvaluator")
assert not hasattr(inire, "DangerMap")
def test_deep_raw_stack_imports_remain_accessible_but_unstable() -> None:
router_module = importlib.import_module("inire.router._router")
search_module = importlib.import_module("inire.router._search")
collision_module = importlib.import_module("inire.geometry.collision")
assert hasattr(router_module, "PathFinder")
assert hasattr(search_module, "route_astar")
assert hasattr(collision_module, "RoutingWorld")
def test_route_problem_smoke() -> None:
problem = RoutingProblem(
bounds=(0, 0, 100, 100),
@ -44,7 +66,7 @@ def test_route_problem_supports_configs_and_debug_data() -> None:
bend_penalty=50.0,
sbend_penalty=150.0,
),
congestion=CongestionOptions(warm_start=None),
congestion=CongestionOptions(warm_start_enabled=False),
refinement=RefinementOptions(enabled=True),
diagnostics=DiagnosticsOptions(capture_expanded=True),
)
@ -61,10 +83,10 @@ def test_route_problem_locked_routes_become_static_obstacles() -> None:
problem = RoutingProblem(
bounds=(0, 0, 100, 100),
nets=(NetSpec("crossing", Port(50, 10, 90), Port(50, 90, 90), width=2.0),),
locked_routes={"locked": LockedRoute.from_path(locked)},
static_obstacles=tuple(polygon for component in locked for polygon in component.physical_geometry),
)
options = RoutingOptions(
congestion=CongestionOptions(max_iterations=1, warm_start=None),
congestion=CongestionOptions(max_iterations=1, warm_start_enabled=False),
refinement=RefinementOptions(enabled=False),
)
@ -86,13 +108,22 @@ def test_locked_routes_enable_incremental_requests_without_sessions() -> None:
problem_b = RoutingProblem(
bounds=(0, -50, 100, 50),
nets=(NetSpec("netB", Port(50, -20, 90), Port(50, 20, 90), width=2.0),),
locked_routes={"netA": results_a.results_by_net["netA"].as_locked_route()},
static_obstacles=results_a.results_by_net["netA"].locked_geometry,
)
results_b = route(problem_b, options=options)
assert results_b.results_by_net["netB"].is_valid
def test_route_problem_rejects_untyped_initial_paths() -> None:
with pytest.raises(TypeError):
RoutingProblem(
bounds=(0, 0, 100, 100),
nets=(NetSpec("net1", Port(10, 50, 0), Port(90, 50, 0), width=2.0),),
initial_paths={"net1": (object(),)}, # type: ignore[dict-item]
)
def test_route_results_metrics_are_snapshots() -> None:
problem = RoutingProblem(
bounds=(0, 0, 100, 100),