"""What this module covers: the cycle's `score_ados2` step (TEA's ADOS-2 CSS and classification, before the association and the silver load) and how the cycle gets the scoring (`webapi.orchestration.eeg.live_ados2_scoring`). Fixtures: none; the graph is built from `webapi.orchestration.cycle` and the scoring is a stand-in. """ from types import SimpleNamespace import pytest from hamilton import driver from webapi.orchestration import cycle, run, steps_of from webapi.orchestration.context import Context from webapi.orchestration.eeg import SCORING_ENV, live_ados2_scoring @pytest.mark.parametrize("proyecto", ["cacu", "cama", "tea"]) def test_the_scoring_runs_before_the_analysis_the_association_and_the_load(proyecto): """Pins down: `score_ados2` needs only the migrated schema and `analyze_eeg` waits for it, so the CSS is written in seconds instead of after a long EEG analysis, and still before the association and the silver load read it. Fails if the scoring moves after the analysis, the association or the load.""" dr = driver.Builder().with_modules(cycle).with_config({"with_cohorts": proyecto == "cacu"}).build() deps = {n.name: {d.name for d in n.dependencies} - {"ctx"} for n in dr.graph.get_nodes() if n.name != "ctx"} assert deps["score_ados2"] == {"migrate"} assert deps["analyze_eeg"] == {"migrate", "score_ados2"} order = steps_of(proyecto) assert order.index("score_ados2") < order.index("analyze_eeg") < order.index("relate_ados2") < order.index("load") def test_the_step_returns_the_scorings_summary_or_nothing(): """Pins down: without a scoring the step is a no-op, and with one it runs it once and returns its summary as a dict. Fails if the step scores when nobody configured it, or stops reporting what it did.""" assert [(p.name, p.summary) for p in run(Context("cacu", 2025, 2025), only=["score_ados2"])] == [ ("score_ados2", {})] calls = [] def scoring(): calls.append(1) from models.ados2_scoring import Summary return Summary(evaluations=5, scored=4, unscored=1) pasos = run(Context("tea", 2025, 2025, ados2_scoring=scoring, repos=SimpleNamespace()), only=["score_ados2"]) assert calls == [1] assert pasos[0].summary == {"evaluations": 5, "scored": 4, "unscored": 1} def test_only_tea_has_the_scoring_and_it_can_be_turned_off(monkeypatch): """Pins down: TEA's cycle gets `models.ados2_scoring.score_pending`, the other domains none, `ADOS2_SCORING=off` leaves it out and an unknown value is refused. Fails if another domain starts scoring, `off` stops working, or a mistyped value silently counts as on.""" from models.ados2_scoring import score_pending monkeypatch.delenv(SCORING_ENV, raising=False) assert live_ados2_scoring("tea") is score_pending assert live_ados2_scoring("cama") is None monkeypatch.setenv(SCORING_ENV, "off") assert live_ados2_scoring("tea") is None monkeypatch.setenv(SCORING_ENV, "maybe") with pytest.raises(ValueError, match=SCORING_ENV): live_ados2_scoring("tea")