From 20c845a881d05c475315680cfd6847f1e63f7d0f Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Tue, 31 Mar 2026 17:12:41 -0700 Subject: [PATCH] [Tool] avoid passing port_names down --- masque/builder/tools.py | 4 ++-- masque/test/test_pather_api.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/masque/builder/tools.py b/masque/builder/tools.py index c14b5d3..5b1a0a9 100644 --- a/masque/builder/tools.py +++ b/masque/builder/tools.py @@ -240,7 +240,7 @@ class Tool: BuildError if an impossible or unsupported geometry is requested. """ # Fallback implementation using traceL - port_names = kwargs.get('port_names', ('A', 'B')) + port_names = kwargs.pop('port_names', ('A', 'B')) tree = self.traceL( ccw, length, @@ -288,7 +288,7 @@ class Tool: BuildError if an impossible or unsupported geometry is requested. """ # Fallback implementation using traceS - port_names = kwargs.get('port_names', ('A', 'B')) + port_names = kwargs.pop('port_names', ('A', 'B')) tree = self.traceS( length, jog, diff --git a/masque/test/test_pather_api.py b/masque/test/test_pather_api.py index c837280..41d0881 100644 --- a/masque/test/test_pather_api.py +++ b/masque/test/test_pather_api.py @@ -2,7 +2,7 @@ import pytest import numpy from numpy import pi from masque import Pather, RenderPather, Library, Pattern, Port -from masque.builder.tools import PathTool +from masque.builder.tools import PathTool, Tool from masque.error import BuildError def test_pather_trace_basic() -> None: @@ -258,6 +258,36 @@ def test_pather_jog_failed_fallback_is_atomic() -> None: assert len(p.paths['A']) == 0 +def test_tool_planL_fallback_accepts_custom_port_names() -> None: + class DummyTool(Tool): + def traceL(self, ccw, length, *, in_ptype=None, out_ptype=None, port_names=('A', 'B'), **kwargs) -> Library: + lib = Library() + pat = Pattern() + pat.ports[port_names[0]] = Port((0, 0), 0, ptype='wire') + pat.ports[port_names[1]] = Port((length, 0), pi, ptype='wire') + lib['top'] = pat + return lib + + out_port, _ = DummyTool().planL(None, 5, port_names=('X', 'Y')) + assert numpy.allclose(out_port.offset, (5, 0)) + assert numpy.isclose(out_port.rotation, pi) + + +def test_tool_planS_fallback_accepts_custom_port_names() -> None: + class DummyTool(Tool): + def traceS(self, length, jog, *, in_ptype=None, out_ptype=None, port_names=('A', 'B'), **kwargs) -> Library: + lib = Library() + pat = Pattern() + pat.ports[port_names[0]] = Port((0, 0), 0, ptype='wire') + pat.ports[port_names[1]] = Port((length, jog), pi, ptype='wire') + lib['top'] = pat + return lib + + out_port, _ = DummyTool().planS(5, 2, port_names=('X', 'Y')) + assert numpy.allclose(out_port.offset, (5, 2)) + assert numpy.isclose(out_port.rotation, pi) + + def test_pather_uturn_failed_fallback_is_atomic() -> None: lib = Library() tool = PathTool(layer='M1', width=2, ptype='wire')