"""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