[Tool] avoid passing port_names down

This commit is contained in:
Jan Petykiewicz 2026-03-31 17:12:41 -07:00
commit 20c845a881
2 changed files with 33 additions and 3 deletions

View file

@ -240,7 +240,7 @@ class Tool:
BuildError if an impossible or unsupported geometry is requested. BuildError if an impossible or unsupported geometry is requested.
""" """
# Fallback implementation using traceL # Fallback implementation using traceL
port_names = kwargs.get('port_names', ('A', 'B')) port_names = kwargs.pop('port_names', ('A', 'B'))
tree = self.traceL( tree = self.traceL(
ccw, ccw,
length, length,
@ -288,7 +288,7 @@ class Tool:
BuildError if an impossible or unsupported geometry is requested. BuildError if an impossible or unsupported geometry is requested.
""" """
# Fallback implementation using traceS # Fallback implementation using traceS
port_names = kwargs.get('port_names', ('A', 'B')) port_names = kwargs.pop('port_names', ('A', 'B'))
tree = self.traceS( tree = self.traceS(
length, length,
jog, jog,

View file

@ -2,7 +2,7 @@ import pytest
import numpy import numpy
from numpy import pi from numpy import pi
from masque import Pather, RenderPather, Library, Pattern, Port 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 from masque.error import BuildError
def test_pather_trace_basic() -> None: 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 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: def test_pather_uturn_failed_fallback_is_atomic() -> None:
lib = Library() lib = Library()
tool = PathTool(layer='M1', width=2, ptype='wire') tool = PathTool(layer='M1', width=2, ptype='wire')