64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from app.main import ReactFlowProjectPayload, run_reactflow_test_mql
|
|
from app.simulation.examples.test_mql.run import prepare_test_mql_run, run_test_mql
|
|
from app.simulation.examples.test_mql.solver import SolveIVPConfig
|
|
from app.simulation.examples.test_mql.system import TestMqlRunConfig
|
|
from app.simulation.paths import PROJECT_ROOT, SIMULATION_RUNS_DIR
|
|
|
|
|
|
class TestMqlExampleRunnerTests(unittest.TestCase):
|
|
def test_test_mql_keeps_calibrated_default_tolerance(self) -> None:
|
|
self.assertEqual(SolveIVPConfig().atol, 1.0e-10)
|
|
|
|
def test_default_run_paths_use_app_simulation_runs_dir(self) -> None:
|
|
prepared = prepare_test_mql_run()
|
|
|
|
self.assertEqual(prepared.repo_root, PROJECT_ROOT)
|
|
self.assertEqual(prepared.output_dir.parent, SIMULATION_RUNS_DIR)
|
|
|
|
def test_zero_duration_run_writes_summary(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
output_dir = Path(directory) / "test_mql"
|
|
result = run_test_mql(
|
|
run_config=TestMqlRunConfig(t_start=0.0, t_stop=0.0),
|
|
output_dir=output_dir,
|
|
)
|
|
|
|
self.assertEqual(result.result.t, [0.0])
|
|
self.assertEqual(result.summary_path, output_dir / "test_mql_model_summary.txt")
|
|
self.assertIn(
|
|
"Model: test_mql",
|
|
result.summary_path.read_text(encoding="utf-8"),
|
|
)
|
|
|
|
def test_reactflow_helper_runs_fixed_topology_test_mql(self) -> None:
|
|
payload = ReactFlowProjectPayload(
|
|
projectSchemaVersion=1,
|
|
name="test-mql-fixed",
|
|
simulation={
|
|
"t_start": 0.0,
|
|
"t_stop": 0.2,
|
|
"step": 0.1,
|
|
"max_step": 0.001,
|
|
"method": "BDF",
|
|
},
|
|
)
|
|
|
|
result = run_reactflow_test_mql(payload)
|
|
|
|
self.assertTrue(result["success"])
|
|
self.assertEqual(result["model"]["name"], "test_mql")
|
|
self.assertEqual(result["model"]["componentCount"], 117)
|
|
self.assertEqual(result["series"]["time"], [0.0, 0.1, 0.2])
|
|
self.assertIn("summary", result["artifacts"])
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|