From f762b86429ac9c935197664c08d58dfaece14b9f Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 29 Nov 2026 23:53:39 -0800 Subject: [PATCH] Validate bend geometry options at construction --- inire/model.py | 15 ++++++++++++--- inire/tests/test_api.py | 12 ++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/inire/model.py b/inire/model.py index 484e878..27e7147 100644 --- a/inire/model.py +++ b/inire/model.py @@ -128,6 +128,18 @@ class SearchOptions(_SearchOptionsCache): _require_nonnegative("distance_heuristic_weight", self.distance_heuristic_weight) if not isfinite(self.proximity_range) or self.proximity_range <= 0: raise ValueError("proximity_range must be finite and positive") + proxy_names = ("arc", "bbox", "clipped_bbox") + for field_name, names, optional in ( + ("bend_collision_type", proxy_names, False), + ("bend_proxy_geometry", proxy_names, True), + ("bend_physical_geometry", ("arc",), True), + ): + geometry = getattr(self, field_name) + if isinstance(geometry, Polygon): + if geometry.is_empty or not geometry.is_valid: + raise ValueError(f"{field_name} must be a valid, nonempty polygon") + elif not ((optional and geometry is None) or (isinstance(geometry, str) and geometry in names)): + raise ValueError(f"Invalid {field_name} {geometry!r}") if self.bend_physical_length is not None: _, physical = resolve_bend_geometry(self) if physical == "arc" or not isfinite(self.bend_physical_length) or self.bend_physical_length <= 0: @@ -159,9 +171,6 @@ class SearchOptions(_SearchOptionsCache): raise ValueError(f"Duplicate S-bend outline for offset {outline.offset}, radius {outline.radius}, width {outline.width}") widths.append(outline.width) object.__setattr__(self, "sbend_outlines", outlines) - for geometry in (self.bend_collision_type, self.bend_proxy_geometry, self.bend_physical_geometry): - if isinstance(geometry, Polygon) and (geometry.is_empty or not geometry.is_valid): - raise ValueError("Custom bend geometry must be a valid, nonempty polygon") if self.bend_physical_geometry is None and isinstance(self.bend_proxy_geometry, Polygon): warnings.warn( "Custom bend proxy provided without bend_physical_geometry; routed bends will keep standard arc geometry.", diff --git a/inire/tests/test_api.py b/inire/tests/test_api.py index 8c14050..30e9d12 100644 --- a/inire/tests/test_api.py +++ b/inire/tests/test_api.py @@ -451,6 +451,18 @@ def test_public_inputs_reject_invalid_ids_and_named_options() -> None: SearchOptions(visibility_guidance="exact") +@pytest.mark.parametrize(("name", "value"), [ + ("bend_collision_type", "clipped-bbox"), + ("bend_collision_type", None), + ("bend_proxy_geometry", "clipped-bbox"), + ("bend_proxy_geometry", 1), + ("bend_physical_geometry", "bbox"), +]) +def test_search_rejects_unsupported_bend_geometry(name, value) -> None: + with pytest.raises(ValueError, match=f"Invalid {name}"): + SearchOptions(**{name: value}) + + def _sbend_strip(offset, half_width=1): centerline = [(0, 0), (20, offset / 10), (50, 3 * offset / 4), (80, offset)] return Polygon(