[Tests] cleanup
This commit is contained in:
parent
d9adb4e1b9
commit
1cce6c1f70
23 changed files with 540 additions and 467 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import pytest
|
||||
import numpy
|
||||
from numpy.testing import assert_equal, assert_allclose
|
||||
from numpy.testing import assert_allclose
|
||||
from numpy import pi
|
||||
|
||||
from ..builder import RenderPather
|
||||
|
|
@ -8,28 +7,30 @@ from ..builder.tools import PathTool
|
|||
from ..library import Library
|
||||
from ..ports import Port
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def rpather_setup():
|
||||
def rpather_setup() -> tuple[RenderPather, PathTool, Library]:
|
||||
lib = Library()
|
||||
tool = PathTool(layer=(1, 0), width=2, ptype="wire")
|
||||
rp = RenderPather(lib, tools=tool)
|
||||
rp.ports["start"] = Port((0, 0), pi/2, ptype="wire")
|
||||
rp.ports["start"] = Port((0, 0), pi / 2, ptype="wire")
|
||||
return rp, tool, lib
|
||||
|
||||
def test_renderpather_basic(rpather_setup):
|
||||
|
||||
def test_renderpather_basic(rpather_setup: tuple[RenderPather, PathTool, Library]) -> None:
|
||||
rp, tool, lib = rpather_setup
|
||||
# Plan two segments
|
||||
rp.at("start").path(ccw=None, length=10).path(ccw=None, length=10)
|
||||
|
||||
|
||||
# Before rendering, no shapes in pattern
|
||||
assert not rp.pattern.has_shapes()
|
||||
assert len(rp.paths["start"]) == 2
|
||||
|
||||
|
||||
# Render
|
||||
rp.render()
|
||||
assert rp.pattern.has_shapes()
|
||||
assert len(rp.pattern.shapes[(1, 0)]) == 1
|
||||
|
||||
|
||||
# Path vertices should be (0,0), (0,-10), (0,-20)
|
||||
# transformed by start port (rot pi/2 -> 270 deg transform)
|
||||
# wait, PathTool.render for opcode L uses rotation_matrix_2d(port_rot + pi)
|
||||
|
|
@ -40,14 +41,15 @@ def test_renderpather_basic(rpather_setup):
|
|||
assert len(path_shape.vertices) == 3
|
||||
assert_allclose(path_shape.vertices, [[0, 0], [0, -10], [0, -20]], atol=1e-10)
|
||||
|
||||
def test_renderpather_bend(rpather_setup):
|
||||
|
||||
def test_renderpather_bend(rpather_setup: tuple[RenderPather, PathTool, Library]) -> None:
|
||||
rp, tool, lib = rpather_setup
|
||||
# Plan straight then bend
|
||||
rp.at("start").path(ccw=None, length=10).path(ccw=False, length=10)
|
||||
|
||||
|
||||
rp.render()
|
||||
path_shape = rp.pattern.shapes[(1, 0)][0]
|
||||
# Path vertices:
|
||||
# Path vertices:
|
||||
# 1. Start (0,0)
|
||||
# 2. Straight end: (0, -10)
|
||||
# 3. Bend end: (-1, -20)
|
||||
|
|
@ -58,16 +60,16 @@ def test_renderpather_bend(rpather_setup):
|
|||
assert len(path_shape.vertices) == 4
|
||||
assert_allclose(path_shape.vertices, [[0, 0], [0, -10], [0, -20], [-1, -20]], atol=1e-10)
|
||||
|
||||
def test_renderpather_retool(rpather_setup):
|
||||
|
||||
def test_renderpather_retool(rpather_setup: tuple[RenderPather, PathTool, Library]) -> None:
|
||||
rp, tool1, lib = rpather_setup
|
||||
tool2 = PathTool(layer=(2, 0), width=4, ptype="wire")
|
||||
|
||||
|
||||
rp.at("start").path(ccw=None, length=10)
|
||||
rp.retool(tool2, keys=["start"])
|
||||
rp.at("start").path(ccw=None, length=10)
|
||||
|
||||
|
||||
rp.render()
|
||||
# Different tools should cause different batches/shapes
|
||||
assert len(rp.pattern.shapes[(1, 0)]) == 1
|
||||
assert len(rp.pattern.shapes[(2, 0)]) == 1
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue