62 lines
2.5 KiB
Python
62 lines
2.5 KiB
Python
import pytest
|
|
from fastapi import HTTPException
|
|
from pydantic import ValidationError
|
|
|
|
from core.domains import Domain
|
|
from webapi.models import Training, train, training_config
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def sync_execution(monkeypatch):
|
|
monkeypatch.setenv("EXECUTION_MODE", "sync")
|
|
|
|
|
|
def test_tea_training_config_schema():
|
|
config = training_config(Domain.TEA, "example").model_dump()
|
|
assert (config["domain"], config["name"]) == ("tea", "example")
|
|
schema = config["json_schema"]
|
|
assert schema["title"] == "TrainingForm"
|
|
assert set(schema["properties"]) == {"as_of", "execution", "source"}
|
|
assert schema["properties"]["as_of"]["title"] == "Datos hasta"
|
|
assert set(schema["$defs"]) == {"Execution", "TrainingSource"}
|
|
execution = schema["$defs"]["Execution"]
|
|
assert execution["title"] == "Ejecución"
|
|
assert execution["properties"]["mode"]["title"] == "Modo"
|
|
assert execution["properties"]["scheduler"]["title"] == "Planificador Dask"
|
|
source = schema["$defs"]["TrainingSource"]
|
|
assert source["title"] == "Datos de entrenamiento"
|
|
assert source["properties"]["kind"]["enum"] == ["site", "folder"]
|
|
assert source["properties"]["folder"]["title"] == "Carpeta"
|
|
assert source["properties"]["line_hz"]["enum"] == [50, 60]
|
|
assert config["defaults"] == {
|
|
"execution": {"mode": "sync", "scheduler": None},
|
|
"source": {"kind": "site", "line_hz": 50},
|
|
}
|
|
|
|
|
|
def test_other_domains_have_no_training_source():
|
|
for domain in ("cacu", "cama"):
|
|
config = training_config(Domain(domain), "example").model_dump()
|
|
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_training_source():
|
|
with pytest.raises(HTTPException) as rejected:
|
|
train(Domain.CACU, Training(source={"kind": "site"}))
|
|
assert rejected.value.status_code == 422
|
|
assert rejected.value.detail == "cacu models take no training source"
|
|
|
|
for source in (
|
|
{"kind": "folder"},
|
|
{"kind": "folder", "folder": "../x"},
|
|
{"kind": "folder", "folder": "hel", "line_hz": 55},
|
|
{"kind": "other"},
|
|
):
|
|
with pytest.raises(ValidationError):
|
|
Training(source=source)
|
|
assert Training(source={"kind": "folder", "folder": "hel"}).source.line_hz == 50
|