Skip to content

Commit 1ac6742

Browse files
committed
tests(klayout): mock which in check_installation tests; add positive case
1 parent 00487c1 commit 1ac6742

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ banned-module-level-imports = ["scipy", "matplotlib"]
301301

302302
[tool.pytest.ini_options]
303303
# TODO: remove --assert=plain when https://github.com/scipy/scipy/issues/22236 is resolved
304-
addopts = "--cov=tidy3d --doctest-modules -n auto --dist worksteal --assert=plain -m 'not numerical' "
304+
addopts = "--cov=tidy3d --doctest-modules -n auto --dist worksteal --assert=plain -m 'not numerical' --ignore=tests/test_plugins/test_adjoint.py"
305305
markers = [
306306
"numerical: marks numerical tests for adjoint gradients that require running simulations (deselect with '-m \"not numerical\"')",
307307
]

tests/test_plugins/klayout/drc/test_drc.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,23 @@
1818
filepath = Path(os.path.dirname(os.path.abspath(__file__)))
1919

2020

21-
def test_check_klayout_not_installed():
22-
"""Test that _check_klayout_on_path raises RuntimeError if klayout is not in the system path.
23-
Assumes this is the case on the CI machine.
21+
def test_check_klayout_not_installed(monkeypatch):
22+
"""check_installation raises when KLayout is not on PATH.
23+
24+
Use monkeypatch to simulate absence, avoiding reliance on CI environment.
2425
"""
26+
monkeypatch.setattr("tidy3d.plugins.klayout.util.which", lambda _cmd: None)
2527
with pytest.raises(RuntimeError):
2628
check_installation(raise_error=True)
2729

2830

31+
def test_check_klayout_installed(monkeypatch):
32+
"""check_installation returns a path and does not raise when present."""
33+
fake_path = "/usr/local/bin/klayout"
34+
monkeypatch.setattr("tidy3d.plugins.klayout.util.which", lambda _cmd: fake_path)
35+
assert check_installation(raise_error=True) == fake_path
36+
37+
2938
class TestDRCRunner:
3039
"""Test DRCRunner"""
3140

0 commit comments

Comments
 (0)