Training config: reference name and mains frequency: GET /models/{domain}/{name}/training-config; POST train accepts reference
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def empty_reference_root(platform, tmp_path):
|
||||
root = tmp_path / "reference"
|
||||
root.mkdir()
|
||||
platform.env["TEA_REFERENCE_ROOT"] = str(root)
|
||||
|
||||
|
||||
def _ok(response):
|
||||
assert response.status_code == 200, response.text
|
||||
return response.json()
|
||||
|
||||
|
||||
def test_tea_training_config_schema(api):
|
||||
config = _ok(api.get("/models/tea/example/training-config"))
|
||||
assert (config["domain"], config["name"]) == ("tea", "example")
|
||||
schema = config["json_schema"]
|
||||
assert schema["title"] == "TrainingForm"
|
||||
assert set(schema["properties"]) == {"as_of", "execution", "reference"}
|
||||
assert schema["properties"]["as_of"]["title"] == "Datos hasta"
|
||||
assert set(schema["$defs"]) == {"Execution", "Reference"}
|
||||
execution = schema["$defs"]["Execution"]
|
||||
assert execution["title"] == "Ejecución"
|
||||
assert execution["properties"]["mode"]["title"] == "Modo"
|
||||
assert execution["properties"]["scheduler"]["title"] == "Planificador Dask"
|
||||
reference = schema["$defs"]["Reference"]["properties"]
|
||||
assert reference["name"]["title"] == "Cohorte de referencia"
|
||||
assert reference["line_hz"]["title"] == "Frecuencia de la red eléctrica (Hz)"
|
||||
assert reference["line_hz"]["enum"] == [50, 60]
|
||||
assert config["defaults"] == {
|
||||
"execution": {"mode": "sync", "scheduler": None},
|
||||
"reference": {"line_hz": 50},
|
||||
}
|
||||
|
||||
|
||||
def test_other_domains_have_no_reference(api):
|
||||
for domain in ("cacu", "cama"):
|
||||
config = _ok(api.get(f"/models/{domain}/example/training-config"))
|
||||
assert (config["domain"], config["name"]) == (domain, "example")
|
||||
schema = config["json_schema"]
|
||||
assert set(schema["properties"]) == {"as_of", "execution"}
|
||||
assert set(schema["$defs"]) == {"Execution"}
|
||||
assert config["defaults"] == {"execution": {"mode": "sync", "scheduler": None}}
|
||||
|
||||
|
||||
def test_train_validates_the_reference(api):
|
||||
response = api.post("/models/cacu/train", json={"reference": {"name": "nope"}})
|
||||
assert response.status_code == 422
|
||||
assert response.json()["detail"] == "cacu models take no reference cohort"
|
||||
|
||||
for reference in ({"name": "../x"}, {"name": "nope", "line_hz": 55}):
|
||||
response = api.post("/models/tea/train", json={"reference": reference})
|
||||
assert response.status_code == 422
|
||||
|
||||
run_id = _ok(api.post("/models/tea/train", json={"reference": {"name": "nope"}}))["run_id"]
|
||||
deadline = time.monotonic() + 120
|
||||
while (run := _ok(api.get(f"/runs/{run_id}")))["state"] in ("queued", "running"):
|
||||
assert time.monotonic() < deadline, run
|
||||
time.sleep(1)
|
||||
assert run["state"] == "failed"
|
||||
assert "no reference cohort 'nope'" in run["error"]
|
||||
Reference in New Issue
Block a user