From 0b4f7593e569ee6c875115ce15553b06dd398281 Mon Sep 17 00:00:00 2001 From: alberto Date: Sun, 29 Nov 2026 01:24:49 -0600 Subject: [PATCH] TEA hospital test follows the sensor flow; re-analysis by id in local mode; first_n Update tests/test_tea_job.py. Use the synthetic TEA builder with the existing pipeline and concept map, ingest via the platform fixture without a daemon, and run first_n synchronously in process. Use SQLite and its temporary platform environment, count an absent analysis table as zero, and clear the cached engine around the in-process calls. --- tests/test_tea_job.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/test_tea_job.py b/tests/test_tea_job.py index 9dddf6b..61f30de 100644 --- a/tests/test_tea_job.py +++ b/tests/test_tea_job.py @@ -1,8 +1,11 @@ -"""The tea_eeg job's graph, its sensor and the config classes, in process (no EEG data).""" +"""The tea_eeg job's graph, sensor, config classes and synthetic EEG scope.""" + +from pathlib import Path import dagster as dg import pytest from pydantic import ValidationError +from sqlalchemy import inspect from models import definitions from models.definitions import ( @@ -14,7 +17,8 @@ from models.definitions import ( tea_eeg_after_ingest, ) from models.tea import jobs as tea_jobs -from persistance import cluster, eeg +from persistance import cluster, destination, eeg +from synthetic import tea def _config(scope: dict) -> dict: @@ -137,3 +141,34 @@ def test_definitions_load_with_every_job_and_the_sensor(): def test_relate_is_a_no_op_until_phase_2(): assert tea_jobs.relate() is None + + +@pytest.mark.parametrize("platform", ["sqlite"], indirect=True) +def test_tea_eeg_first_n_analyses_exactly_n(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: + table = "bronze.eeg_analysis" + with destination.engine().connect() as con: + has_analysis = inspect(con).has_table("eeg_analysis", schema="bronze") + before = platform.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 platform.count(table) == before + 3 + assert len(eeg.pending()) == pending - 3 + finally: + destination.engine.cache_clear()