89dac1e979
Algorithm scores 0, 1, 2, 3 -> 0, 1, 2, 2 and 7, 8, 9 -> 0, with the Toddler B-1 exception (1 -> 2). The algorithm column comes from completed months and item A-1 (new catalog field language_level): Toddler 12-20 months few words, 21-30 by A-1; Module 1 by A-1; Module 2 under five or not. The total adds only the column's items. Classification from the manual's total cuts; Toddler CSS from Esler 2015 table 3; Modules 1-2 CSS from the manual's comparison tables (test transcription, in code for now). Module 3 is not scored (no items in the ADOS-2 list). Labels non_tea / autism_spectrum / autism and little_or_no / mild_to_moderate / moderate_to_severe concern. A-1 travels to FHIR, follow-up (ados2_language_level), association input, synthetic hospital, pipelines and the Gobernanza preview. Ported from the tea library 0.4.0 (patches 0001/0002).
98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
import hashlib
|
|
import os
|
|
from datetime import date
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
from dagster import build_op_context
|
|
|
|
from core.pipeline import Extract
|
|
from models.definitions import Preview, preview_study
|
|
from models.tea import preview as study
|
|
from persistance import config, previews
|
|
|
|
|
|
@pytest.fixture
|
|
def preview_area(monkeypatch, tmp_path):
|
|
monkeypatch.setattr(config, "DATA_DIR", tmp_path)
|
|
return previews.area()
|
|
|
|
|
|
def test_previews_area(preview_area):
|
|
key = previews.put(b"file")
|
|
assert key == hashlib.sha256(b"file").hexdigest()
|
|
os.utime(preview_area / key, (1, 1))
|
|
assert previews.put(b"file") == key
|
|
assert (preview_area / key).stat().st_mtime == 1
|
|
assert previews.get(key) == b"file"
|
|
for invalid in ("../x", "abc"):
|
|
with pytest.raises(ValueError):
|
|
previews.get(invalid)
|
|
with pytest.raises(LookupError, match=f"no preview file {'0' * 64}"):
|
|
previews.get("0" * 64)
|
|
previews.discard([key, None, "0" * 64])
|
|
assert not (preview_area / key).exists()
|
|
|
|
old = previews.put(b"old")
|
|
recent = previews.put(b"recent")
|
|
os.utime(preview_area / old, (1, 1))
|
|
assert previews.sweep() == 1
|
|
assert {path.name for path in preview_area.iterdir()} == {recent}
|
|
|
|
|
|
def test_an_unreadable_file_is_a_result_not_a_crash():
|
|
result = study.preview(b"nope")
|
|
assert result.eeg.valid is False
|
|
assert result.eeg.checks
|
|
assert result.ados2 is None
|
|
assert result.eeg.recorded_on is None
|
|
|
|
|
|
def test_the_job_deletes_its_files_and_returns_the_result_as_output(preview_area):
|
|
edf = previews.put(b"not an EDF")
|
|
report = previews.put(b"not a PDF")
|
|
with build_op_context() as context:
|
|
result = preview_study(context, Preview(edf=edf, ados2=report))
|
|
assert result == {"valid": False, "warnings": 1}
|
|
assert list(preview_area.iterdir()) == []
|
|
|
|
|
|
def test_the_job_deletes_its_files_when_the_study_fails(preview_area):
|
|
report = previews.put(b"%PDF")
|
|
with build_op_context() as context, pytest.raises(LookupError, match="no preview file"):
|
|
preview_study(context, Preview(edf="0" * 64, ados2=report))
|
|
assert list(preview_area.iterdir()) == []
|
|
|
|
|
|
@pytest.mark.parametrize("language, css", [(3, 1), (1, 2)])
|
|
def test_ados2_preview_reads_language_level_and_scores_its_column(monkeypatch, language, css):
|
|
node = Extract(
|
|
id="ados2",
|
|
column="text",
|
|
entity="ados2",
|
|
patterns={
|
|
"module": r"Módulo (module_1)",
|
|
"language_level": r"A-1 (\d)",
|
|
"vocalization_directed": r"A-2 (\d)",
|
|
"intonation": r"A-3 (\d)",
|
|
"stereotyped_language": r"A-5 (\d)",
|
|
},
|
|
)
|
|
monkeypatch.setattr(
|
|
study.graph,
|
|
"read_file",
|
|
lambda _: {
|
|
"text": f"Módulo module_1\nA-1 {language}\nA-2 2\nA-3 3\nA-5 3",
|
|
"error": None,
|
|
},
|
|
)
|
|
monkeypatch.setattr(study.config_log, "get", lambda _: (1, SimpleNamespace(nodes=[node])))
|
|
warnings = []
|
|
result = study._report(b"%PDF", "tea", date(2026, 1, 1), date(2023, 7, 1), warnings)
|
|
assert result.items["language_level"] == language
|
|
assert next(iter(result.items)) == "language_level"
|
|
assert result.titles["language_level"] == "A-1 Nivel general de lenguaje oral no ecolálico"
|
|
assert result.css == css
|
|
assert result.classification == "non_tea"
|
|
assert warnings == []
|