Merge parity/F1a
This commit is contained in:
@@ -10,7 +10,7 @@ from webapi.models import training_inputs, upload_training_inputs
|
|||||||
def test_training_inputs(tmp_path, monkeypatch):
|
def test_training_inputs(tmp_path, monkeypatch):
|
||||||
root = tmp_path / "reference"
|
root = tmp_path / "reference"
|
||||||
monkeypatch.setenv("TEA_REFERENCE_ROOT", str(root))
|
monkeypatch.setenv("TEA_REFERENCE_ROOT", str(root))
|
||||||
assert training_inputs(Domain.TEA, "curve_x")["sets"] == []
|
assert training_inputs(Domain.TEA, "curve_x") == {"allowed": ["*.edf", "edades.csv"]}
|
||||||
with pytest.raises(HTTPException) as undefined:
|
with pytest.raises(HTTPException) as undefined:
|
||||||
training_inputs(Domain.TEA, "ados2_association")
|
training_inputs(Domain.TEA, "ados2_association")
|
||||||
assert undefined.value.status_code == 404
|
assert undefined.value.status_code == 404
|
||||||
@@ -25,7 +25,6 @@ def test_training_inputs(tmp_path, monkeypatch):
|
|||||||
|
|
||||||
expected = {"name": "cohort", "edf_files": 1, "has_ages": True, "bytes": 7}
|
expected = {"name": "cohort", "edf_files": 1, "has_ages": True, "bytes": 7}
|
||||||
assert upload("cohort", [("one.EDF", b"edf"), ("edades.csv", b"ages")]) == expected
|
assert upload("cohort", [("one.EDF", b"edf"), ("edades.csv", b"ages")]) == expected
|
||||||
assert training_inputs(Domain.TEA, "curve_x")["sets"] == [expected]
|
|
||||||
|
|
||||||
for invalid in ("bad.txt", "../x"):
|
for invalid in ("bad.txt", "../x"):
|
||||||
with pytest.raises(HTTPException) as rejected:
|
with pytest.raises(HTTPException) as rejected:
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ from fastapi import HTTPException
|
|||||||
from pydantic import ValidationError
|
from pydantic import ValidationError
|
||||||
|
|
||||||
from core.domains import Domain
|
from core.domains import Domain
|
||||||
|
from persistance.cluster import FolderTrainingSource
|
||||||
|
from webapi import models
|
||||||
from webapi.models import Training, train, training_config
|
from webapi.models import Training, train, training_config
|
||||||
|
|
||||||
|
|
||||||
@@ -18,19 +20,36 @@ def test_tea_training_config_schema():
|
|||||||
assert schema["title"] == "TrainingForm"
|
assert schema["title"] == "TrainingForm"
|
||||||
assert set(schema["properties"]) == {"as_of", "execution", "source"}
|
assert set(schema["properties"]) == {"as_of", "execution", "source"}
|
||||||
assert schema["properties"]["as_of"]["title"] == "Datos hasta"
|
assert schema["properties"]["as_of"]["title"] == "Datos hasta"
|
||||||
assert set(schema["$defs"]) == {"Execution", "TrainingSource"}
|
assert set(schema["$defs"]) == {
|
||||||
|
"Execution",
|
||||||
|
"TrainingSource",
|
||||||
|
"SiteTrainingSource",
|
||||||
|
"FolderTrainingSource",
|
||||||
|
}
|
||||||
execution = schema["$defs"]["Execution"]
|
execution = schema["$defs"]["Execution"]
|
||||||
assert execution["title"] == "Ejecución"
|
assert execution["title"] == "Ejecución"
|
||||||
assert execution["properties"]["mode"]["title"] == "Modo"
|
assert execution["properties"]["mode"]["title"] == "Modo"
|
||||||
assert execution["properties"]["scheduler"]["title"] == "Planificador Dask"
|
assert execution["properties"]["scheduler"]["title"] == "Planificador Dask"
|
||||||
source = schema["$defs"]["TrainingSource"]
|
source = schema["$defs"]["TrainingSource"]
|
||||||
assert source["title"] == "Datos de entrenamiento"
|
assert source["discriminator"] == {
|
||||||
assert source["properties"]["kind"]["enum"] == ["site", "folder"]
|
"propertyName": "kind",
|
||||||
assert source["properties"]["folder"]["title"] == "Carpeta"
|
"mapping": {
|
||||||
assert source["properties"]["line_hz"]["enum"] == [50, 60]
|
"site": "#/$defs/SiteTrainingSource",
|
||||||
|
"folder": "#/$defs/FolderTrainingSource",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert source["oneOf"] == [
|
||||||
|
{"$ref": "#/$defs/SiteTrainingSource"},
|
||||||
|
{"$ref": "#/$defs/FolderTrainingSource"},
|
||||||
|
]
|
||||||
|
site = schema["$defs"]["SiteTrainingSource"]
|
||||||
|
assert set(site["properties"]) == {"kind"}
|
||||||
|
folder = schema["$defs"]["FolderTrainingSource"]
|
||||||
|
assert folder["properties"]["folder"]["title"] == "Carpeta"
|
||||||
|
assert folder["properties"]["line_hz"]["enum"] == [50, 60]
|
||||||
assert config["defaults"] == {
|
assert config["defaults"] == {
|
||||||
"execution": {"mode": "sync", "scheduler": None},
|
"execution": {"mode": "sync", "scheduler": None},
|
||||||
"source": {"kind": "site", "line_hz": 50},
|
"source": {"kind": "site"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -54,8 +73,33 @@ def test_train_validates_the_training_source():
|
|||||||
{"kind": "folder"},
|
{"kind": "folder"},
|
||||||
{"kind": "folder", "folder": "../x"},
|
{"kind": "folder", "folder": "../x"},
|
||||||
{"kind": "folder", "folder": "hel", "line_hz": 55},
|
{"kind": "folder", "folder": "hel", "line_hz": 55},
|
||||||
|
{"kind": "site", "folder": "hel"},
|
||||||
|
{"kind": "site", "line_hz": 60},
|
||||||
{"kind": "other"},
|
{"kind": "other"},
|
||||||
):
|
):
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
Training(source=source)
|
Training(source=source)
|
||||||
assert Training(source={"kind": "folder", "folder": "hel"}).source.line_hz == 50
|
assert Training(source={"kind": "site"}).model_dump()["source"] == {"kind": "site"}
|
||||||
|
folder = Training(source={"kind": "folder", "folder": "hel"}).source
|
||||||
|
assert isinstance(folder, FolderTrainingSource)
|
||||||
|
assert folder.line_hz == 50
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"source",
|
||||||
|
[
|
||||||
|
{"kind": "site"},
|
||||||
|
{"kind": "folder", "folder": "hel", "line_hz": 60},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_train_submits_the_selected_source(monkeypatch, source):
|
||||||
|
client = object()
|
||||||
|
|
||||||
|
def submit(actual_client, job, op, config, *, domain):
|
||||||
|
assert actual_client is client
|
||||||
|
assert (job, op, domain) == ("train", "train_models", "tea")
|
||||||
|
assert config["source"] == source
|
||||||
|
return {"run_id": "training"}
|
||||||
|
|
||||||
|
monkeypatch.setattr(models, "submit", submit)
|
||||||
|
assert train(Domain.TEA, Training(source=source), client) == {"run_id": "training"}
|
||||||
|
|||||||
+6
-5
@@ -195,9 +195,9 @@ def _training_inputs(domain: Domain, name: str) -> tuple[InputSpec, Path]:
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/{domain}/{name}/inputs")
|
@router.get("/{domain}/{name}/inputs")
|
||||||
def training_inputs(domain: Domain, name: str) -> dict:
|
def training_inputs(domain: Domain, name: str) -> dict[str, list[str]]:
|
||||||
spec, root = _training_inputs(domain, name)
|
spec, _ = _training_inputs(domain, name)
|
||||||
return {"description": spec.description, "allowed": spec.allowed, "sets": inputs.sets(root)}
|
return {"allowed": spec.allowed}
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{domain}/{name}/inputs/{set}/files")
|
@router.post("/{domain}/{name}/inputs/{set}/files")
|
||||||
@@ -256,10 +256,11 @@ def training_config(domain: Domain, name: str) -> TrainingConfig:
|
|||||||
json_schema = TrainingForm.model_json_schema()
|
json_schema = TrainingForm.model_json_schema()
|
||||||
defaults = {"execution": {"mode": cluster.default_mode(), "scheduler": None}}
|
defaults = {"execution": {"mode": cluster.default_mode(), "scheduler": None}}
|
||||||
if domain == Domain.TEA:
|
if domain == Domain.TEA:
|
||||||
defaults["source"] = {"kind": "site", "line_hz": 50}
|
defaults["source"] = {"kind": "site"}
|
||||||
else:
|
else:
|
||||||
del json_schema["properties"]["source"]
|
del json_schema["properties"]["source"]
|
||||||
del json_schema["$defs"]["TrainingSource"]
|
for definition in ("TrainingSource", "SiteTrainingSource", "FolderTrainingSource"):
|
||||||
|
del json_schema["$defs"][definition]
|
||||||
return TrainingConfig(
|
return TrainingConfig(
|
||||||
domain=domain.value, name=name, json_schema=json_schema, defaults=defaults
|
domain=domain.value, name=name, json_schema=json_schema, defaults=defaults
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user