[OASIS] raise PatternError for unsuppored caps
This commit is contained in:
parent
2952e6ef8f
commit
4b07bb9e25
2 changed files with 19 additions and 1 deletions
|
|
@ -562,7 +562,9 @@ def _shapes_to_elements(
|
||||||
xy = rint_cast(shape.offset + shape.vertices[0] + rep_offset)
|
xy = rint_cast(shape.offset + shape.vertices[0] + rep_offset)
|
||||||
deltas = rint_cast(numpy.diff(shape.vertices, axis=0))
|
deltas = rint_cast(numpy.diff(shape.vertices, axis=0))
|
||||||
half_width = rint_cast(shape.width / 2)
|
half_width = rint_cast(shape.width / 2)
|
||||||
path_type = next(k for k, v in path_cap_map.items() if v == shape.cap) # reverse lookup
|
path_type = next((k for k, v in path_cap_map.items() if v == shape.cap), None) # reverse lookup
|
||||||
|
if path_type is None:
|
||||||
|
raise PatternError(f'OASIS writer does not support path cap {shape.cap}')
|
||||||
extension_start = (path_type, shape.cap_extensions[0] if shape.cap_extensions is not None else None)
|
extension_start = (path_type, shape.cap_extensions[0] if shape.cap_extensions is not None else None)
|
||||||
extension_end = (path_type, shape.cap_extensions[1] if shape.cap_extensions is not None else None)
|
extension_end = (path_type, shape.cap_extensions[1] if shape.cap_extensions is not None else None)
|
||||||
path = fatrec.Path(
|
path = fatrec.Path(
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
|
import io
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import pytest
|
import pytest
|
||||||
from numpy.testing import assert_equal
|
from numpy.testing import assert_equal
|
||||||
|
|
||||||
|
from ..error import PatternError
|
||||||
from ..pattern import Pattern
|
from ..pattern import Pattern
|
||||||
from ..library import Library
|
from ..library import Library
|
||||||
|
from ..shapes import Path as MPath
|
||||||
|
|
||||||
|
|
||||||
def test_oasis_roundtrip(tmp_path: Path) -> None:
|
def test_oasis_roundtrip(tmp_path: Path) -> None:
|
||||||
|
|
@ -42,3 +45,16 @@ def test_oasis_properties_to_annotations_merges_repeated_keys() -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
assert annotations == {"k": [1, 2, 3]}
|
assert annotations == {"k": [1, 2, 3]}
|
||||||
|
|
||||||
|
|
||||||
|
def test_oasis_write_rejects_circle_path_caps() -> None:
|
||||||
|
pytest.importorskip("fatamorgana")
|
||||||
|
from ..file import oasis
|
||||||
|
|
||||||
|
lib = Library()
|
||||||
|
pat = Pattern()
|
||||||
|
pat.path((1, 0), vertices=[[0, 0], [10, 0]], width=2, cap=MPath.Cap.Circle)
|
||||||
|
lib["cell1"] = pat
|
||||||
|
|
||||||
|
with pytest.raises(PatternError, match="does not support path cap"):
|
||||||
|
oasis.write(lib, io.BytesIO(), units_per_micron=1000)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue