import pytest from edf_files import small_edf from pydantic import ValidationError from models.tea import jobs from persistance.cluster import Reference @pytest.fixture def cohort(tmp_path, monkeypatch): monkeypatch.setenv("TEA_REFERENCE_ROOT", str(tmp_path)) monkeypatch.delenv("TEA_REFERENCE_CACHE", raising=False) folder = tmp_path / "hel" folder.mkdir() for i in range(3): small_edf(folder / f"{i}.edf") ages = folder / "edades.csv" ages.write_text("name,age\n0.edf,1.5\n1.edf,2.0\n2.edf,2.5\n") return folder, ages def test_bad_references_fail_with_a_reason(cohort): folder, ages = cohort for name in ("..", ".", "nope"): with pytest.raises(ValueError) as exc: jobs._reference(Reference(name=name)) assert str(exc.value) == f"no reference cohort {name!r}" ages.write_text("name,age\n0.edf,1\n1.edf,4\n2.edf,5\n") with pytest.raises( ValueError, match="reference cohort 'hel' has no EDF with an age from 16 to 36 months" ): jobs._reference(Reference(name="hel")) ages.unlink() with pytest.raises(ValueError, match=r"reference cohort 'hel' has no edades\.csv"): jobs._reference(Reference(name="hel")) with pytest.raises(ValidationError, match="name"): Reference(name="../x") with pytest.raises(ValidationError, match="line_hz"): Reference(name="hel", line_hz=55)