28858c6966
The same dataflow, cohort, index and prediction index as the CIN2+ surveillance model, with carcinoma as the only event, like the cancer column of KPNC's tables: the patient's two risks are of the same visit. The subgroup report template serves it too.
37 lines
1.9 KiB
Python
37 lines
1.9 KiB
Python
"""What this module covers: `models.reports.templates`: the notebooks kept in the code are listed by domain with the
|
|
scenarios they can run for, read by id, and an id outside their layout is refused."""
|
|
|
|
import pytest
|
|
|
|
from models.reports.templates import notebook_templates, template_notebook
|
|
|
|
|
|
def test_the_cacu_templates_are_listed_with_the_scenarios_they_serve():
|
|
"""Pins down: CaCu's subgroup reports are listed; the PIM one serves every scenario whose dataflow lists its
|
|
report, the survival one only its own. Fails if a template stops being found or its scenarios stop following the
|
|
`model.toml` modules."""
|
|
found = {t["id"]: t for t in notebook_templates("cacu")}
|
|
|
|
pim, survival = found["cacu/cin2_pim/reporte_subgrupos"], found["cacu/survival/reporte_subgrupos"]
|
|
assert pim["scenarios"] == ["cancer_pim", "cin2_pim", "cin2_pim_post_colposcopy", "cin2_pim_post_treatment"]
|
|
assert survival["scenarios"] == ["survival"] and survival["domain"] == "cacu" and survival["title"]
|
|
|
|
|
|
def test_a_template_is_read_by_its_id():
|
|
"""Pins down: an id gives the template's name and its notebook (nbformat 4). Fails if the id stops naming the
|
|
file under `models/<domain>/<scenario>/notebooks/`."""
|
|
name, notebook = template_notebook("cacu/survival/reporte_subgrupos")
|
|
|
|
assert name == "reporte_subgrupos" and notebook["nbformat"] == 4 and notebook["cells"]
|
|
|
|
|
|
@pytest.mark.parametrize("template_id, error", [
|
|
("cacu/survival/../../io/x", ValueError), ("cacu/../../etc/passwd", ValueError), ("otro/survival/x", ValueError),
|
|
("cacu/survival/no_existe", LookupError), ("", ValueError),
|
|
])
|
|
def test_an_id_outside_the_templates_is_refused(template_id, error):
|
|
"""Pins down: an id with other characters, another domain, or no such file is refused before anything is read.
|
|
Fails if a crafted id reaches a file outside the templates."""
|
|
with pytest.raises(error):
|
|
template_notebook(template_id)
|