meanas/meanas/test/test_examples_smoke.py
2026-07-14 00:21:34 -07:00

60 lines
1.8 KiB
Python

from pathlib import Path
import os
import re
import subprocess
import sys
import pytest
pytestmark = pytest.mark.complete
REPO_ROOT = Path(__file__).resolve().parents[2]
def _run_example(example_name: str, tmp_path: Path) -> subprocess.CompletedProcess[str]:
env = os.environ.copy()
env['MPLBACKEND'] = 'Agg'
env['MPLCONFIGDIR'] = str(tmp_path / f'mpl-{example_name}')
return subprocess.run(
[sys.executable, str(REPO_ROOT / 'examples' / example_name)],
cwd=REPO_ROOT,
env=env,
text=True,
capture_output=True,
check=False,
timeout=60,
)
def test_eme_example_smoke_runs(tmp_path: Path) -> None:
pytest.importorskip('matplotlib')
result = _run_example('eme.py', tmp_path)
assert result.returncode == 0, result.stdout + result.stderr
assert 'left effective indices:' in result.stdout
assert 'fundamental left-to-right transmission' in result.stdout
def test_eme_bend_example_smoke_runs(tmp_path: Path) -> None:
pytest.importorskip('matplotlib')
pytest.importorskip('skrf')
result = _run_example('eme_bend.py', tmp_path)
assert result.returncode == 0, result.stdout + result.stderr
assert 'straight effective indices:' in result.stdout
assert 'cascaded bend through power' in result.stdout
straight_index_match = re.search(r'straight effective indices:\s*([0-9.]+)', result.stdout)
assert straight_index_match is not None, result.stdout
assert float(straight_index_match.group(1)) > 1.6
def test_eme_taper_cmt_example_smoke_runs(tmp_path: Path) -> None:
result = _run_example('eme_taper_cmt.py', tmp_path)
assert result.returncode == 0, result.stdout + result.stderr
assert 'sampled taper effective indices:' in result.stdout
assert 'taper CMT transmission' in result.stdout