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

Working on mocks

parent 84e5967f
...@@ -34,6 +34,7 @@ def test_project_path() -> Path: ...@@ -34,6 +34,7 @@ def test_project_path() -> Path:
# SimStadt mock (replaces subprocess call with fixture file copying) # SimStadt mock (replaces subprocess call with fixture file copying)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
def _find_fixture_flow(provider: str) -> Path | None: def _find_fixture_flow(provider: str) -> Path | None:
"""Find a .flow directory in test data that matches the given provider and has output files.""" """Find a .flow directory in test data that matches the given provider and has output files."""
for flow_dir in TEST_REPOSITORY.rglob("*.flow"): for flow_dir in TEST_REPOSITORY.rglob("*.flow"):
...@@ -43,7 +44,9 @@ def _find_fixture_flow(provider: str) -> Path | None: ...@@ -43,7 +44,9 @@ def _find_fixture_flow(provider: str) -> Path | None:
root = et.parse(params_xml).getroot() root = et.parse(params_xml).getroot()
elem = root.find(".//void[@property='workflowProvider']/object") elem = root.find(".//void[@property='workflowProvider']/object")
if elem is not None and elem.get("class") == provider: if elem is not None and elem.get("class") == provider:
non_params = [f for f in flow_dir.rglob("*") if f.is_file() and f.name != "params.xml"] non_params = [
f for f in flow_dir.rglob("*") if f.is_file() and f.name != "params.xml"
]
if non_params: if non_params:
return flow_dir return flow_dir
return None return None
...@@ -53,7 +56,7 @@ def _find_fixture_flow(provider: str) -> Path | None: ...@@ -53,7 +56,7 @@ def _find_fixture_flow(provider: str) -> Path | None:
def mock_simstadt(monkeypatch): def mock_simstadt(monkeypatch):
"""Mock run_simstadt by copying fixture output files instead of running SimStadt.""" """Mock run_simstadt by copying fixture output files instead of running SimStadt."""
def _mock(workflow_path: Path, name: str) -> str: def _mock(workflow_path: Path, name: str, csv_export: bool = False) -> str:
root = et.parse(workflow_path / "params.xml").getroot() root = et.parse(workflow_path / "params.xml").getroot()
elem = root.find(".//void[@property='workflowProvider']/object") elem = root.find(".//void[@property='workflowProvider']/object")
provider = elem.get("class") if elem is not None else None provider = elem.get("class") if elem is not None else None
...@@ -74,13 +77,13 @@ def mock_simstadt(monkeypatch): ...@@ -74,13 +77,13 @@ def mock_simstadt(monkeypatch):
# Live fixtures (require SimStadt to be installed) # Live fixtures (require SimStadt to be installed)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def simstadt_folder(): def simstadt_folder():
"""Skip the test if SimStadt is not installed.""" """Skip the test if SimStadt is not installed."""
from simstadt.runner import get_simstadt_folder from simstadt.runner import get_simstadt_folder
try: try:
return get_simstadt_folder() return get_simstadt_folder()
except ValueError as e: except ValueError as e:
pytest.skip(str(e)) pytest.skip(str(e))
...@@ -91,7 +91,7 @@ def test_run_files_flag(mock_simstadt, run_cli, capsys, tmp_path): ...@@ -91,7 +91,7 @@ def test_run_files_flag(mock_simstadt, run_cli, capsys, tmp_path):
assert "Mean Uvalue" in out assert "Mean Uvalue" in out
def _broken_simstadt(_workflow_path: Path, _name: str) -> str: def _broken_simstadt(_workflow_path: Path, _name: str, _csv_export: bool = False) -> str:
raise ValueError("BOOM!") raise ValueError("BOOM!")
......
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