tests: say why each timeline orchestration test exists #6

Merged
edgar merged 1 commits from feature/model-proto into dev 2026-11-04 11:33:15 -06:00
+24 -1
View File
@@ -1,4 +1,10 @@
"""The timeline repository wired by `repositorios_de` reads the same rows as the kit, in each project."""
"""What this module covers: the timeline repository that `repositorios_de` wires into `ctx.repos.plata`
reads the same rows as the kit's own query, in each project.
Fixtures: `base` (from `conftest.py`), a project database for each of CaCu, CaMa and TEA; each test loads
its catalogs and data with `base.correr("catalogos", "cargar")`. `kit_rows` reads the same timeline
straight through the kit (`filas_de_linea`) to compare against.
"""
from datetime import date, datetime, timedelta, timezone
from importlib import import_module
@@ -11,12 +17,19 @@ CORTE = date(2025, 12, 31)
def kit_rows(base, **filters):
"""The project's timeline read through the kit with `filters` (the kit's Spanish keywords)."""
fuentes = import_module(f"indicadores_kit.{base.proyecto}.linea_de_tiempo").FUENTES_PLATA
with Session(base.motor) as session:
return filas_de_linea(session, tablas_de(base.proyecto), fuentes, **filters)
def test_the_whole_timeline_matches_the_kit(base):
"""Pins down: with only a clinical cut-off, the wired repository returns exactly the kit's rows, and
there are some.
Fails if the orchestration binds another query, another project's tables or sources, or `until`
stops reaching the kit as `hasta`.
"""
base.correr("catalogos", "cargar")
rows = base.ctx.repos.plata.timeline.read(until=CORTE)
assert rows
@@ -24,6 +37,11 @@ def test_the_whole_timeline_matches_the_kit(base):
def test_the_patient_filter_matches_the_kit(base):
"""Pins down: `patients` reaches the kit as `pacientes`: only those patients come back, with the
kit's rows.
Fails if the patient filter is dropped or renamed on the way to the kit's query.
"""
base.correr("catalogos", "cargar")
patients = sorted({row["pac_id"] for row in kit_rows(base)})[:2]
rows = base.ctx.repos.plata.timeline.read(patients=patients, until=CORTE)
@@ -32,6 +50,11 @@ def test_the_patient_filter_matches_the_kit(base):
def test_known_until_cuts_at_what_was_loaded(base):
"""Pins down: `known_until` reaches the kit as `conocida_hasta`: before the load nothing is known,
after it everything is, the same as reading without the cut.
Fails if the load cut-off is ignored, or applied to the clinical date instead of the load time.
"""
before = datetime.now(timezone.utc) - timedelta(days=1)
base.correr("catalogos", "cargar")
after = datetime.now(timezone.utc) + timedelta(days=1)