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.
This commit is contained in:
+37
-2
@@ -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 dagster as dg
|
||||||
import pytest
|
import pytest
|
||||||
from pydantic import ValidationError
|
from pydantic import ValidationError
|
||||||
|
from sqlalchemy import inspect
|
||||||
|
|
||||||
from models import definitions
|
from models import definitions
|
||||||
from models.definitions import (
|
from models.definitions import (
|
||||||
@@ -14,7 +17,8 @@ from models.definitions import (
|
|||||||
tea_eeg_after_ingest,
|
tea_eeg_after_ingest,
|
||||||
)
|
)
|
||||||
from models.tea import jobs as tea_jobs
|
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:
|
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():
|
def test_relate_is_a_no_op_until_phase_2():
|
||||||
assert tea_jobs.relate() is None
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user