Files
models/tests/reports/test_rendering.py
T
edgar e8c264e571 Subgroup reports for CaCu's survival and PIM scenarios, as version files and as notebooks in the code
Every CaCu PIM scenario (cin2_pim, post-colposcopy, post-treatment) and the survival scenario now keep, per
combination of their covariates, the model against its empirical estimate, with the methods each used:

- PIM (models/cacu/cin2_pim/report.py): Turnbull's interval-censored estimate (prevalent = mass at 0, free in (l, r],
  unknown baseline in [0, r]; ported from bayes-pim chapter 24) with a bootstrap band, against the mixture refitted on
  every coded member with a delta-method band over the likelihood (inverse numerical Hessian, numerical gradient of
  CR(t), log scale); E/O at each horizon with log(E/O) taken as normal.
- Survival (models/cacu/survival/report.py): Kaplan-Meier with Greenwood's band against the SEER pipeline's own
  subgroup points and bootstrap interval (survival_curves.sv_sub_weights and sv_sub_points, called as they are).

A version keeps the record as analisis/subgrupos.json and a self-contained Plotly page as reportes/subgrupos.html
(TrainingRun.log_report; the saver publishes a dataflow's `reports`). The same drawing is a notebook in the code,
models/cacu/{cin2_pim,survival}/notebooks/reporte_subgrupos.ipynb: chart names and computed results only, a
`parameters` cell, `#| echo: false` cells. models.reports.templates lists those notebooks with the scenarios each serves
and reads one by id, for the WebApi's /governance/notebook-templates. The Jupyter renderer now drops the code of
`#| echo: false` cells, as Quarto does.

plotly>=5.18 joins the `survival-curves` extra (installed by the WebApi) and the dev group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-21 22:41:04 -06:00

22 lines
1.2 KiB
Python

"""What this module covers: `models.reports.rendering.JupyterRenderer`'s page keeps out the code of a cell that asks for
it as Quarto does (`#| echo: false`) and keeps its output, so a notebook renders the same with either renderer.
No kernel runs: the cells carry their outputs already."""
import nbformat
from nbconvert import HTMLExporter
from models.reports.rendering import JupyterRenderer
def test_a_cell_with_echo_false_shows_its_output_and_not_its_code():
"""Pins down: the hidden cell's source (a marker in its code) is not on the page, its output is, and a cell without
the option still shows its code. Fails if the Jupyter renderer stops honouring `#| echo: false`."""
hidden = nbformat.v4.new_code_cell("#| echo: false\nsecret_marker_in_code = 1\nprint('salida visible')")
hidden.outputs = [nbformat.v4.new_output("stream", name="stdout", text="salida visible\n")]
shown = nbformat.v4.new_code_cell("codigo_que_se_ve = 2")
node = nbformat.v4.new_notebook(cells=[hidden, shown])
page = JupyterRenderer._page(HTMLExporter, node)
assert "salida visible" in page and "secret_marker_in_code" not in page and "codigo_que_se_ve" in page