[arrow] improve test coverage and error handling
This commit is contained in:
parent
f3a60da30b
commit
151a7f846f
3 changed files with 160 additions and 9 deletions
|
|
@ -1,11 +1,15 @@
|
|||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import klamath
|
||||
import numpy
|
||||
import pytest
|
||||
|
||||
pytest.importorskip('pyarrow')
|
||||
|
||||
from .. import Ref, Label
|
||||
from .. import Ref, Label, PatternError
|
||||
from ..library import Library
|
||||
from ..pattern import Pattern
|
||||
from ..repetition import Grid
|
||||
|
|
@ -175,6 +179,26 @@ def _make_arrow_test_library() -> Library:
|
|||
return lib
|
||||
|
||||
|
||||
def _write_invalid_path_type_fixture(path: Path) -> None:
|
||||
with path.open('wb') as stream:
|
||||
header = klamath.library.FileHeader(
|
||||
name=b'test',
|
||||
user_units_per_db_unit=1.0,
|
||||
meters_per_db_unit=1e-9,
|
||||
)
|
||||
header.write(stream)
|
||||
elem = klamath.elements.Path(
|
||||
layer=(1, 0),
|
||||
path_type=3,
|
||||
width=10,
|
||||
extension=(0, 0),
|
||||
xy=numpy.array([[0, 0], [10, 0]], dtype=numpy.int32),
|
||||
properties={},
|
||||
)
|
||||
klamath.library.write_struct(stream, name=b'top', elements=[elem])
|
||||
klamath.records.ENDLIB.write(stream, None)
|
||||
|
||||
|
||||
def test_gdsii_arrow_matches_gdsii_readfile(tmp_path: Path) -> None:
|
||||
lib = _make_arrow_test_library()
|
||||
gds_file = tmp_path / 'arrow_roundtrip.gds'
|
||||
|
|
@ -238,6 +262,28 @@ def test_gdsii_arrow_removed_raw_mode_arg(tmp_path: Path) -> None:
|
|||
gdsii_arrow.read_arrow(libarr, raw_mode=False)
|
||||
|
||||
|
||||
def test_gdsii_arrow_invalid_input_raises_klamath_error(tmp_path: Path) -> None:
|
||||
gds_file = tmp_path / 'invalid.gds'
|
||||
gds_file.write_bytes(b'not-a-gds')
|
||||
|
||||
script = textwrap.dedent(f"""
|
||||
from masque.file import gdsii_arrow
|
||||
try:
|
||||
gdsii_arrow.readfile({str(gds_file)!r})
|
||||
except Exception as exc:
|
||||
print(type(exc).__module__)
|
||||
print(type(exc).__qualname__)
|
||||
print(exc)
|
||||
else:
|
||||
raise SystemExit('expected gdsii_arrow.readfile() to fail')
|
||||
""")
|
||||
result = subprocess.run([sys.executable, '-c', script], capture_output=True, text=True, check=False)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert 'klamath.basic' in result.stdout
|
||||
assert 'KlamathError' in result.stdout
|
||||
|
||||
|
||||
def test_gdsii_arrow_reads_small_perf_fixture(tmp_path: Path) -> None:
|
||||
gds_file = tmp_path / 'many_cells_smoke.gds'
|
||||
manifest = write_fixture(gds_file, preset='many_cells', scale=0.001)
|
||||
|
|
@ -435,6 +481,17 @@ def test_gdsii_arrow_ref_schema(tmp_path: Path) -> None:
|
|||
assert aref_props[0]['properties'][0]['value'] == 'fanout-aref'
|
||||
|
||||
|
||||
def test_gdsii_arrow_invalid_path_type_matches_gdsii(tmp_path: Path) -> None:
|
||||
gds_file = tmp_path / 'invalid_path_type.gds'
|
||||
_write_invalid_path_type_fixture(gds_file)
|
||||
|
||||
with pytest.raises(PatternError, match='Unrecognized path type: 3'):
|
||||
gdsii.readfile(gds_file)
|
||||
|
||||
with pytest.raises(PatternError, match='Unrecognized path type: 3'):
|
||||
gdsii_arrow.readfile(gds_file)
|
||||
|
||||
|
||||
def test_raw_ref_grid_label_constructors_match_public() -> None:
|
||||
raw_grid = Grid._from_raw(
|
||||
a_vector=numpy.array([20, 0]),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue