FastAPI server, replaceable JSON config, tests, Dockerfile. Pairs with ATO via spec/interface.md contract. Co-authored-by: Cursor <cursoragent@cursor.com>
26 lines
688 B
Python
26 lines
688 B
Python
import os
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
os.environ.setdefault("SIM_CONFIG", "config/sim.default.json")
|
|
os.environ.setdefault("TRACK_CONFIG", "config/track.default.json")
|
|
|
|
from trainsim.app import create_app # noqa: E402
|
|
|
|
client = TestClient(create_app())
|
|
|
|
|
|
def test_health():
|
|
assert client.get("/health").json()["status"] == "ok"
|
|
|
|
|
|
def test_state_shape():
|
|
s = client.get("/train/state").json()
|
|
assert "speed_mps" in s and "track_length_m" in s
|
|
|
|
|
|
def test_actuate_and_start():
|
|
client.post("/sim/start")
|
|
client.post("/train/actuate", json={"traction_pct": 50, "brake_pct": 0})
|
|
s = client.get("/train/state").json()
|
|
assert s["sim_running"] is True
|