Commit e8327ddc authored by Eric Duminil's avatar Eric Duminil
Browse files

Mocking SimStadt for faster tests

parent e2afa436
......@@ -19,7 +19,7 @@ def test_project_path() -> Path:
# ---------------------------------------------------------------------------
# SimStadt spoof (replaces subprocess call with fixture file copying)
# SimStadt mock (replaces subprocess call with fixture file copying)
# ---------------------------------------------------------------------------
def _find_fixture_flow(provider: str) -> Path | None:
......@@ -38,10 +38,10 @@ def _find_fixture_flow(provider: str) -> Path | None:
@pytest.fixture
def spoof_simstadt(monkeypatch):
"""Patch run_simstadt to copy fixture output files instead of running SimStadt."""
def mock_simstadt(monkeypatch):
"""Mock run_simstadt by copying fixture output files instead of running SimStadt."""
def _spoof(workflow_path: Path, name: str) -> str:
def _mock(workflow_path: Path, name: str) -> str:
root = et.parse(workflow_path / "params.xml").getroot()
elem = root.find(".//void[@property='workflowProvider']/object")
provider = elem.get("class") if elem is not None else None
......@@ -53,9 +53,9 @@ def spoof_simstadt(monkeypatch):
dst = workflow_path / src.relative_to(fixture_flow)
dst.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(src, dst)
return f"Spoofed SimStadt for {name}"
return f"Mocked SimStadt for {name}"
monkeypatch.setattr("simstadt.runner.run_simstadt", _spoof)
monkeypatch.setattr("simstadt.runner.run_simstadt", _mock)
# ---------------------------------------------------------------------------
......
......@@ -3,42 +3,42 @@
import shutil
from pathlib import Path
import pytest
from simstadt.runner import run_workflow_with_citygml
TEST_DATA = Path(__file__).parent / "data"
CITYGML = TEST_DATA / "TestRepo" / "MiniBuchwald.gml"
TEMPLATE = TEST_DATA / "Templates" / "01_HeatDemand"
TEMPLATE1 = TEST_DATA / "Templates" / "01_HeatDemand"
TEMPLATE2 = TEST_DATA / "Templates" / "02_LoadProfile"
TEMPLATE3 = TEST_DATA / "Templates" / "03_PV"
def test_citygml_in_proj_folder(spoof_simstadt, tmp_path):
def test_citygml_in_proj_folder(mock_simstadt, tmp_path):
"""CityGML already inside a .proj folder — used as-is, nothing copied."""
proj = tmp_path / "Test.proj"
proj.mkdir()
gml = proj / CITYGML.name
shutil.copy(CITYGML, gml)
results = run_workflow_with_citygml(TEMPLATE, gml)
results = run_workflow_with_citygml(TEMPLATE1, gml)
assert results is not None
assert CITYGML.name in results.citygml
assert results.workflow_path.parent == proj
def test_citygml_with_explicit_project_path(spoof_simstadt, tmp_path):
def test_citygml_with_explicit_project_path(mock_simstadt, tmp_path):
"""CityGML outside .proj with project_path — CityGML is copied to project_path."""
proj = tmp_path / "Test.proj"
proj.mkdir()
results = run_workflow_with_citygml(TEMPLATE, CITYGML, project_path=proj)
results = run_workflow_with_citygml(TEMPLATE2, CITYGML, project_path=proj)
assert (proj / CITYGML.name).exists()
assert results is not None
assert results.workflow_path.parent == proj
def test_citygml_with_explicit_project_path_no_double_copy(spoof_simstadt, tmp_path):
def test_citygml_with_explicit_project_path_no_double_copy(mock_simstadt, tmp_path):
"""CityGML already present in project_path — not copied again."""
proj = tmp_path / "Test.proj"
proj.mkdir()
......@@ -46,14 +46,14 @@ def test_citygml_with_explicit_project_path_no_double_copy(spoof_simstadt, tmp_p
shutil.copy(CITYGML, dest)
mtime_before = dest.stat().st_mtime
run_workflow_with_citygml(TEMPLATE, CITYGML, project_path=proj)
run_workflow_with_citygml(TEMPLATE3, CITYGML, project_path=proj)
assert dest.stat().st_mtime == mtime_before
def test_citygml_creates_temp_repo(spoof_simstadt):
def test_citygml_creates_temp_repo(mock_simstadt):
"""CityGML outside .proj with no project_path — temporary repository created."""
results = run_workflow_with_citygml(TEMPLATE, CITYGML)
results = run_workflow_with_citygml(TEMPLATE1, CITYGML)
assert results is not None
assert "simstadt_repo" in str(results.workflow_path)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment