The suite keeps only logic tests

Keep deterministic model, signal, DSL and SQLite storage checks.

Checks: ruff check, ruff format --check, lint-imports (two contracts kept), and pytest (115 passed, 7 warnings in 42.52s).

removed models/tests/test_bundle.py::test_guard_runs_on_export_and_on_import — implementation-detail
removed models/tests/test_cacu_models.py — parity-only
removed models/tests/test_cacu_models.py::test_predictions_match_the_current_models — parity-only
removed models/tests/test_cacu_models.py::test_survival_matches_the_current_model_with_its_index_fixed — parity-only
removed models/tests/test_cacu_models.py::test_a_cohort_the_site_lacks_is_reported_not_trained — implementation-detail
removed models/tests/test_cama_models.py — parity-only
removed models/tests/test_cama_models.py::test_survival_matches_the_current_model — parity-only
removed models/tests/test_edf_node.py — slow integration (logic now covered by test_header_reads_the_facts, test_not_an_edf_is_not_valid and test_collected_files_are_kept_once_by_content)
removed models/tests/test_edf_node.py::test_edf_pipeline_keeps_and_links_the_files — slow integration (logic now covered by test_header_reads_the_facts, test_not_an_edf_is_not_valid and test_collected_files_are_kept_once_by_content)
removed models/tests/test_edf_upload.py — slow integration (logic now covered by test_tea_eeg_first_n_selects_exactly_n_pending_studies for study selection)
removed models/tests/test_edf_upload.py::test_an_uploaded_edf_is_analysed_by_itself — slow integration (logic now covered by test_tea_eeg_first_n_selects_exactly_n_pending_studies for study selection)
removed models/tests/test_eeg.py::test_verdicts_and_checks — parity-only
removed models/tests/test_eeg.py::test_metric_values — parity-only
removed models/tests/test_eeg.py::test_reference_features — parity-only
removed models/tests/test_eeg.py::test_curves — parity-only
removed models/tests/test_execution.py::test_map_empty_items_starts_nothing — implementation-detail
removed models/tests/test_execution.py::test_map_local_equals_sync — slow integration (logic now covered by test_map_sync_keeps_input_order_and_reports_each_item)
removed models/tests/test_execution.py::test_map_lazy_items_are_not_all_loaded_at_once — implementation-detail
removed models/tests/test_execution.py::test_progress_tag_and_log_lines_inside_running — implementation-detail
removed models/tests/test_execution.py::test_no_tag_outside_running — implementation-detail
removed models/tests/test_execution.py::test_version_mismatch_fails_before_any_task — implementation-detail
removed models/tests/test_execution.py::test_local_cancel_leaves_no_worker_processes — slow integration (logic now covered by test_cancel_returns_the_terminal_or_cancelling_state for cancellation states)
removed models/tests/test_execution.py::test_health_sync_and_local — slow integration (logic now covered by test_resolve_defaults_and_allow_list for execution defaults)
removed models/tests/test_execution.py::test_health_unreachable_remote — slow integration (logic now covered by test_resolve_rejects_unlisted_scheduler_and_scheduler_in_local_mode for scheduler validation)
removed models/tests/test_execution.py::test_health_rejects_unlisted_scheduler — implementation-detail
removed models/tests/test_execution.py::test_progress_reaches_the_dagster_run — slow integration (logic now covered by test_shape_progress_tag and test_map_sync_keeps_input_order_and_reports_each_item)
removed models/tests/test_execution.py::test_map_remote_equals_sync — slow integration (logic now covered by test_map_sync_keeps_input_order_and_reports_each_item)
removed models/tests/test_execution.py::test_health_remote — slow integration (logic now covered by test_resolve_defaults_and_allow_list for remote execution choice)
removed models/tests/test_execution.py::test_remote_cancel_cancels_futures — slow integration (logic now covered by test_cancel_returns_the_terminal_or_cancelling_state for cancellation states)
removed models/tests/test_execution.py::test_progress_json_is_stable — implementation-detail
removed models/tests/test_execution.py::test_map_on_error_converts_a_failed_item[local] — slow integration (logic now covered by test_map_on_error_converts_a_failed_item)
removed models/tests/test_execution.py::test_map_raises_without_on_error[local] — slow integration (logic now covered by test_map_raises_without_on_error)
removed models/tests/test_ingest.py — slow integration (logic now covered by test_collected_files_are_kept_once_by_content and test_the_drawn_patterns_read_every_report)
removed models/tests/test_ingest.py::test_a_site_reaches_bronze_once_and_its_documents_are_read — slow integration (logic now covered by test_collected_files_are_kept_once_by_content and test_the_drawn_patterns_read_every_report)
removed models/tests/test_recurrence.py::test_cohorts — parity-only
removed models/tests/test_recurrence.py::test_routines — parity-only
removed models/tests/test_recurrence.py::test_c_index_and_internal_auc — parity-only
removed models/tests/test_recurrence.py::test_saved_model — parity-only
removed models/tests/test_recurrence.py::test_calculator — parity-only
removed models/tests/test_recurrence.py::test_risk_factors — parity-only
removed models/tests/test_recurrence.py::test_train_reproduces_v1 — parity-only
removed models/tests/test_silver.py::test_a_site_becomes_silver_and_review_gets_the_rest — slow integration (logic now covered by test_person_ids_survive_a_review_merge_and_split and test_a_code_nobody_mapped_is_held_with_the_reason)
removed models/tests/test_survival_seer.py — parity-only
removed models/tests/test_survival_seer.py::test_each_scenario_takes_the_originals_patients_and_deaths — parity-only
removed models/tests/test_survival_seer.py::test_each_scenarios_observed_curves_are_the_originals — parity-only
removed models/tests/test_survival_seer.py::test_the_models_points_are_the_survival_of_the_cases_it_learned_from — parity-only
removed models/tests/test_tea_association.py::test_reference_parity — parity-only
removed models/tests/test_tea_job.py::test_tea_eeg_runs_the_four_steps_in_order — implementation-detail
removed models/tests/test_tea_job.py::test_a_failing_analysis_stops_the_graph — implementation-detail
removed models/tests/test_tea_job.py::test_a_bad_scope_fails_before_any_work — implementation-detail
removed models/tests/test_tea_job.py::test_config_mirrors_match_the_shared_models — implementation-detail
removed models/tests/test_tea_job.py::test_definitions_load_with_every_job_and_the_sensor — implementation-detail
removed models/tests/test_tea_job.py::test_relate_returns_none_without_a_champion — implementation-detail
removed models/tests/test_tea_job.py::test_tea_eeg_first_n_analyses_exactly_n — slow integration (logic now covered by test_tea_eeg_first_n_selects_exactly_n_pending_studies)
removed models/tests/test_tea_job.py::test_tea_eeg_remote_mode_gives_the_same_analysis — slow integration (logic now covered by test_dominant_peak_recovers_a_posterior_rhythm_above_background and test_centile_interpolation_preserves_scoring)
removed models/tests/test_tea_preview.py::test_scores_come_from_the_champions — implementation-detail
removed models/tests/test_tea_preview.py::test_no_champions_warns_and_leaves_z_empty — implementation-detail
removed models/tests/test_tea_preview.py::test_ados2_read_with_the_pipeline_patterns — implementation-detail
removed models/tests/test_tea_preview.py::test_ados2_problems_are_warnings_not_errors — implementation-detail
removed models/tests/test_tea_preview.py::test_the_job_deletes_its_files_and_returns_the_result_as_output — slow integration (logic now covered by the direct-op test_the_job_deletes_its_files_and_returns_the_result_as_output)
removed models/tests/test_tea_preview.py::test_the_job_deletes_its_files_when_the_study_fails — implementation-detail
removed models/tests/test_tea_reference.py::test_a_named_reference_resolves_under_the_root — implementation-detail
removed models/tests/test_tea_reference.py::test_60_hz_changes_the_digest_and_is_passed_on — implementation-detail
removed models/tests/test_tea_reference.py::test_the_cache_is_named_by_cohort_and_digest_and_reused — implementation-detail
removed models/tests/test_tea_reference.py::test_legacy_environment_still_works — implementation-detail
removed models/tests/test_tea_reference.py::test_train_records_cohort_and_line_hz — implementation-detail
removed models/tests/test_tea_reference.py::test_the_train_op_passes_the_reference_or_refuses_it — implementation-detail
removed models/tests/test_tea_reference.py::test_reference_config_mirrors_the_shared_model — implementation-detail
This commit is contained in:
2026-11-30 16:45:51 -06:00
parent d8445fcabf
commit c1a1e294dc
16 changed files with 118 additions and 2196 deletions
+13 -179
View File
@@ -1,17 +1,11 @@
import hashlib
import os
from datetime import date
from types import SimpleNamespace
import dagster as dg
import pytest
from dagster import build_op_context
from core import tea
from core.pipeline import Extract, Pipeline, Source
from core.tea import ados2
from models.definitions import tea_preview
from models.definitions import Preview, preview_study
from models.tea import preview as study
from models.tea.eeg import analysis, curves
from persistance import config, previews
@@ -51,177 +45,17 @@ def test_an_unreadable_file_is_a_result_not_a_crash():
assert result.eeg.recorded_on is None
@pytest.fixture
def valid_study(monkeypatch):
metric = analysis.Metric("paroxysmal_spikes", 3, {"F3": 3, "F4": 0}, {"frontal": 3})
analysed = analysis.Analysis(
valid=True,
level="valid",
age_months=42,
clean_fraction=1,
bad_channels=0,
channels=19,
duration_min=20,
line_noise_db=None,
sleep=True,
checks=[],
metrics=[metric],
features={"eeg-spikes": {curves.EXPOSURE: 20}},
error=None,
)
monkeypatch.setattr(analysis, "analyze", lambda *_: analysed)
def test_scores_come_from_the_champions(monkeypatch, valid_study):
baseline = dict.fromkeys(("value", "electrode_F3", "zone_frontal"))
model = SimpleNamespace(unwrap_python_model=lambda: SimpleNamespace(baseline=baseline))
monkeypatch.setattr(study.registry, "champion", lambda _: (3, model))
score = {"z": 1, "outside": 0, "p5": 0, "median": 2, "p95": 4}
def deviations(models, analysed):
assert set(models) == set(curves.SCENARIOS)
assert analysed.metrics[0].electrodes == {"F3": 3}
return {
"paroxysmal_spikes": {
"value": score,
"electrodes": {"F3": score},
"zones": {"frontal": score},
}
}
monkeypatch.setattr(curves, "deviations", deviations)
result = study.preview(b"edf")
metric = result.eeg.metrics[0]
assert metric.score == previews.Score(**score)
assert metric.electrodes == {
"F3": previews.Site(value=3, score=previews.Score(**score)),
"F4": previews.Site(value=0, score=None),
}
assert metric.zones == {"frontal": previews.Site(value=3, score=previews.Score(**score))}
assert metric.model == "tea.eeg-spikes/3"
assert not result.warnings
def test_no_champions_warns_and_leaves_z_empty(monkeypatch, valid_study):
monkeypatch.setattr(study.registry, "champion", lambda _: None)
result = study.preview(b"edf")
assert result.warnings == ["there are no champion age curves: no z is shown"]
metric = result.eeg.metrics[0]
assert metric.score is metric.model is None
assert all(site.score is None for site in (metric.electrodes | metric.zones).values())
def _pipeline(patterns):
return Pipeline(
nodes=[
Source(id="source", source="dlt.sources.sql_database:sql_table"),
Extract(
id="x",
inputs=["source"],
column="text",
entity="ados2",
method="patterns",
patterns=patterns,
), # fmt: skip
]
)
def test_ados2_read_with_the_pipeline_patterns(monkeypatch):
text = "module module_1; date 2025-01-01; pointing 2; gestures 1; intonation 3"
patterns = {
"module": r"module (\w+)",
"evaluation_date": r"date ([\d-]+)",
"pointing": r"pointing (\d+)",
"gestures": r"gestures (\d+)",
"intonation": r"intonation (\d+)",
}
monkeypatch.setattr(study.graph, "read_file", lambda _: {"text": text, "error": None})
monkeypatch.setattr(study.config_log, "get", lambda _: (1, _pipeline(patterns)))
birth = date(2022, 1, 1)
result = study.preview(b"edf", b"%PDF", birth)
row = dict(module="module_1", evaluation_date=date(2025, 1, 1),
pointing=2, gestures=1, intonation=3) # fmt: skip
assert result.ados2 is not None
assert result.ados2.items == {
name: row.get(name) for name in tea.SOCIAL_AFFECT_ITEMS + tea.RESTRICTED_REPETITIVE_ITEMS
}
assert result.ados2.module == row["module"]
assert result.ados2.evaluation_date == row["evaluation_date"]
assert result.ados2.read == sorted(row)
assert (result.ados2.css, result.ados2.classification) == ados2.score(row, birth)
assert not result.warnings
def test_ados2_problems_are_warnings_not_errors(monkeypatch):
def check(report, *warnings):
result = study.preview(b"edf", report)
assert result.eeg == study.preview(b"edf").eeg
assert result.warnings == list(warnings)
return result.ados2
assert check(b"text", "the ADOS-2 file is not a PDF") is None
monkeypatch.setattr(study.graph, "read_file", lambda _: {"error": "broken"})
assert check(b"%PDF", "the ADOS-2 report could not be read: broken") is None
def missing(_):
raise LookupError("tea")
text = "pointing bad; date 2025-01-01"
monkeypatch.setattr(study.graph, "read_file", lambda _: {"text": text, "error": None})
monkeypatch.setattr(study.config_log, "get", missing)
assert check(b"%PDF", "no saved pipeline tea: the ADOS-2 report is not read") is None
monkeypatch.setattr(study.config_log, "get", lambda _: (1, Pipeline(nodes=[])))
assert check(b"%PDF", "pipeline tea has no ados2 extract node") is None
monkeypatch.setattr(
study.config_log, "get", lambda _: (1, _pipeline({"module": r"missing (.)"}))
)
assert check(b"%PDF", "no ADOS-2 field was found in the report") is None
patterns = {"pointing": r"pointing (\w+)"}
monkeypatch.setattr(study.config_log, "get", lambda _: (1, _pipeline(patterns)))
report = check(
b"%PDF",
"pointing: could not read 'bad' as a number",
"ADOS-2 not scored: no evaluation date",
)
assert report is not None
assert report.read == ["pointing"]
assert report.items["pointing"] is report.css is report.classification is None
patterns = {"evaluation_date": r"date ([\d-]+)"}
report = check(
b"%PDF",
"the ADOS-2 score could not be calculated: the report lacks the module or the item scores",
)
assert report is not None
assert report.css is report.classification is None
def _execute(key, ados_key, *, raise_on_error=True):
with dg.DagsterInstance.ephemeral() as instance:
return tea_preview.execute_in_process(
run_config={"ops": {"preview_study": {"config": {"edf": key, "ados2": ados_key}}}},
instance=instance,
raise_on_error=raise_on_error,
)
def test_the_job_deletes_its_files_and_returns_the_result_as_output(preview_area):
run = _execute(previews.put(b"edf"), previews.put(b"not a report"))
assert run.success
assert not list(preview_area.iterdir())
assert run.output_for_node("preview_study") == {"valid": False, "warnings": 1}
(event,) = run.filter_events(lambda event: event.event_type == dg.DagsterEventType.STEP_OUTPUT)
result = previews.PreviewResult.model_validate(event.step_output_data.metadata["result"].value)
assert result.eeg.valid is False
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(monkeypatch, preview_area):
def failed(*_):
raise RuntimeError("study failed")
monkeypatch.setattr(study, "preview", failed)
run = _execute(previews.put(b"edf"), previews.put(b"%PDF"), raise_on_error=False)
assert not run.success
assert not 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()) == []