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:
+28
-172
@@ -1,83 +1,11 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from datetime import date
|
||||
|
||||
import dagster as dg
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
from sqlalchemy import inspect
|
||||
|
||||
from models import definitions, execution
|
||||
from models.definitions import (
|
||||
ExecutionConfig,
|
||||
ScopeConfig,
|
||||
after_ingest,
|
||||
defs,
|
||||
tea_eeg,
|
||||
tea_eeg_after_ingest,
|
||||
)
|
||||
from models.tea import jobs as tea_jobs
|
||||
from persistance import cluster, destination, eeg
|
||||
from synthetic import tea
|
||||
|
||||
|
||||
def _config(scope: dict) -> dict:
|
||||
return {"ops": {"tea_analyze_studies": {"config": {
|
||||
"scope": scope, "execution": {"mode": "sync"}}}}} # fmt: skip
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def calls(monkeypatch):
|
||||
log = []
|
||||
|
||||
def analyze(scope=None, *, rebuild_gold=True):
|
||||
log.append(("analyze", scope, rebuild_gold))
|
||||
return 2
|
||||
|
||||
monkeypatch.setattr(tea_jobs, "analyze", analyze)
|
||||
monkeypatch.setattr(tea_jobs, "score_curves", lambda: log.append(("score",)) or {"c": 3})
|
||||
monkeypatch.setattr(tea_jobs, "relate", lambda: log.append(("relate",)))
|
||||
monkeypatch.setattr(definitions.silver, "build", lambda sel: log.append(("build", sel)))
|
||||
return log
|
||||
|
||||
|
||||
def test_tea_eeg_runs_the_four_steps_in_order(calls):
|
||||
result = tea_eeg.execute_in_process(
|
||||
instance=dg.DagsterInstance.ephemeral(), run_config=_config({"mode": "first_n", "n": 2})
|
||||
)
|
||||
assert result.success
|
||||
assert [c[0] for c in calls] == ["analyze", "score", "relate", "build"]
|
||||
assert calls[0][1].n == 2 and calls[0][2] is False
|
||||
assert calls[3][1] == tea_jobs.GOLD_SELECT
|
||||
assert result.output_for_node("tea_analyze_studies") == {"analysed": 2}
|
||||
assert result.output_for_node("tea_score_curves") == {"scored": {"c": 3}}
|
||||
assert result.output_for_node("tea_relate_ados2") == {"ados2_association": None}
|
||||
assert result.output_for_node("tea_build_gold") == {"built": tea_jobs.GOLD_SELECT}
|
||||
|
||||
|
||||
def test_a_failing_analysis_stops_the_graph(calls, monkeypatch):
|
||||
def boom(scope=None, *, rebuild_gold=True):
|
||||
raise RuntimeError("no signal")
|
||||
|
||||
monkeypatch.setattr(tea_jobs, "analyze", boom)
|
||||
result = tea_eeg.execute_in_process(
|
||||
instance=dg.DagsterInstance.ephemeral(),
|
||||
run_config=_config({"mode": "pending"}),
|
||||
raise_on_error=False,
|
||||
)
|
||||
assert not result.success
|
||||
assert calls == []
|
||||
|
||||
|
||||
def test_a_bad_scope_fails_before_any_work(calls):
|
||||
result = tea_eeg.execute_in_process(
|
||||
instance=dg.DagsterInstance.ephemeral(),
|
||||
run_config=_config({"mode": "first_n"}),
|
||||
raise_on_error=False,
|
||||
)
|
||||
assert not result.success
|
||||
assert calls == []
|
||||
failure = next(e for e in result.all_events if e.is_step_failure)
|
||||
assert "first_n needs n" in str(failure.event_specific_data.error)
|
||||
from models.definitions import ScopeConfig, after_ingest
|
||||
from persistance import eeg
|
||||
|
||||
|
||||
def test_scope_validation():
|
||||
@@ -108,17 +36,6 @@ def test_scope_validation():
|
||||
ScopeConfig(mode="first_n").model()
|
||||
|
||||
|
||||
def test_config_mirrors_match_the_shared_models():
|
||||
for config, shared in ((ScopeConfig, eeg.Scope), (ExecutionConfig, cluster.Execution)):
|
||||
assert list(config.model_fields) == list(shared.model_fields)
|
||||
for name, field in shared.model_fields.items():
|
||||
assert config.model_fields[name].default == field.default, name
|
||||
with pytest.raises(ValidationError):
|
||||
ExecutionConfig(mode="cloud").model()
|
||||
with pytest.raises(ValidationError):
|
||||
ScopeConfig(mode="all").model()
|
||||
|
||||
|
||||
def test_after_ingest_requests_a_run_only_with_pending_eegs():
|
||||
skip = after_ingest("r1", lambda: False)
|
||||
assert isinstance(skip, dg.SkipReason)
|
||||
@@ -130,92 +47,31 @@ def test_after_ingest_requests_a_run_only_with_pending_eegs():
|
||||
assert request.tags["domain"] == "tea" and request.tags["triggered_by"] == "r1"
|
||||
|
||||
|
||||
def test_definitions_load_with_every_job_and_the_sensor():
|
||||
dg.Definitions.validate_loadable(defs)
|
||||
names = {j.name for j in defs.jobs}
|
||||
assert names >= {"ingest", "train", "score", "analyze", "tea_eeg"}
|
||||
assert tea_eeg_after_ingest.default_status == dg.DefaultSensorStatus.RUNNING
|
||||
|
||||
|
||||
def test_relate_returns_none_without_a_champion():
|
||||
assert tea_jobs.relate() is None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def synthetic_tea(platform, tmp_path, monkeypatch):
|
||||
tea.build(tmp_path / "hospital_tea.db")
|
||||
fixtures = Path(__file__).parents[2] / "tests" / "fixtures"
|
||||
drawing = tmp_path / "pipeline.json"
|
||||
drawing.write_text(
|
||||
(fixtures / "pipelines" / "hospital_tea.json")
|
||||
.read_text()
|
||||
.replace("{hospital}", str(tmp_path))
|
||||
)
|
||||
platform.save("concept_maps", "hospital_tea", fixtures / "concept_maps" / "hospital_tea.json")
|
||||
platform.save("pipelines", "tea", drawing)
|
||||
platform.ingest("tea")
|
||||
|
||||
for name in ("PLATFORM_DATABASE_URL", "DLT_DATA_DIR", "EXECUTION_MODE"):
|
||||
monkeypatch.setenv(name, platform.env[name])
|
||||
monkeypatch.setattr(destination, "DATA_DIR", tmp_path)
|
||||
destination.engine.cache_clear()
|
||||
try:
|
||||
yield platform
|
||||
finally:
|
||||
destination.engine.cache_clear()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platform", ["sqlite"], indirect=True)
|
||||
def test_tea_eeg_first_n_analyses_exactly_n(synthetic_tea):
|
||||
table = "bronze.eeg_analysis"
|
||||
with destination.engine().connect() as con:
|
||||
has_analysis = inspect(con).has_table("eeg_analysis", schema="bronze")
|
||||
before = synthetic_tea.count(table) if has_analysis else 0
|
||||
pending = len(eeg.pending())
|
||||
tea_jobs.analyze(eeg.Scope(mode="first_n", n=3), rebuild_gold=False)
|
||||
assert synthetic_tea.count(table) == before + 3
|
||||
assert len(eeg.pending()) == pending - 3
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not os.environ.get("DASK_TEST_SCHEDULER"), reason="DASK_TEST_SCHEDULER is not set"
|
||||
)
|
||||
@pytest.mark.parametrize("platform", ["sqlite"], indirect=True)
|
||||
def test_tea_eeg_remote_mode_gives_the_same_analysis(synthetic_tea):
|
||||
def snapshot():
|
||||
analyses = synthetic_tea.query(
|
||||
"select edf, valid, level, age_months, clean_fraction, bad_channels "
|
||||
"from bronze.eeg_analysis order by edf"
|
||||
def test_tea_eeg_first_n_selects_exactly_n_pending_studies(fresh_platform):
|
||||
with fresh_platform.begin() as con:
|
||||
con.exec_driver_sql("create table silver.person (person_id text, birth_date text)")
|
||||
con.exec_driver_sql("insert into silver.person values ('p1', '2023-01-01')")
|
||||
con.exec_driver_sql("create table silver.eeg (person_id text, study_date text, edf text)")
|
||||
con.exec_driver_sql(
|
||||
"insert into silver.eeg values (?, ?, ?)",
|
||||
[
|
||||
("p1", "2025-01-01", "c"),
|
||||
("p1", "2025-02-01", "b"),
|
||||
("p1", "2025-03-01", "a"),
|
||||
("p1", "2025-04-01", "d"),
|
||||
("p1", "2025-05-01", None),
|
||||
],
|
||||
)
|
||||
metrics = synthetic_tea.query(
|
||||
"select edf, code, value from bronze.eeg_metrics order by edf, code"
|
||||
)
|
||||
return analyses, metrics
|
||||
con.exec_driver_sql("create table bronze.eeg_analysis (edf text)")
|
||||
con.exec_driver_sql("insert into bronze.eeg_analysis values ('b')")
|
||||
|
||||
assert tea_jobs.analyze(eeg.Scope(mode="first_n", n=2), rebuild_gold=False) == 2
|
||||
before, metrics_before = snapshot()
|
||||
ids = [study["id"] for study in eeg.studies() if study["analysed"]]
|
||||
assert len(ids) == 2
|
||||
|
||||
@dg.op
|
||||
def remote_analysis(context):
|
||||
remote = cluster.Execution(mode="remote", scheduler=os.environ["DASK_TEST_SCHEDULER"])
|
||||
with execution.running(context, remote):
|
||||
return tea_jobs.analyze(eeg.Scope(mode="ids", ids=ids), rebuild_gold=False)
|
||||
|
||||
@dg.job
|
||||
def reanalyze():
|
||||
remote_analysis()
|
||||
|
||||
result = reanalyze.execute_in_process()
|
||||
assert result.success
|
||||
assert result.output_for_node("remote_analysis") == 2
|
||||
after, metrics_after = snapshot()
|
||||
|
||||
def close(value):
|
||||
return pytest.approx(value, rel=1e-12) if isinstance(value, float) else value
|
||||
|
||||
assert [tuple(row) for row in after] == [tuple(map(close, row)) for row in before]
|
||||
assert [tuple(row) for row in metrics_after] == [
|
||||
tuple(map(close, row)) for row in metrics_before
|
||||
birth = date(2023, 1, 1)
|
||||
assert eeg.select(eeg.Scope(mode="first_n", n=2)) == [
|
||||
{"edf": "a", "birth_date": birth},
|
||||
{"edf": "c", "birth_date": birth},
|
||||
]
|
||||
assert eeg.select(eeg.Scope(mode="ids", ids=["p1|2025-02-01"])) == [
|
||||
{"edf": "b", "birth_date": birth}
|
||||
]
|
||||
with pytest.raises(LookupError, match="has no signal"):
|
||||
eeg.select(eeg.Scope(mode="ids", ids=["p1|2025-05-01"]))
|
||||
|
||||
Reference in New Issue
Block a user