Skip to content

Commit c8a212a

Browse files
test(export): exercise the real webpdf render path
The test registered `_inline_code_wrap_css` itself, so it verified the preprocessor worked but not that production wired it up; dropping the `register_preprocessor` call in `_render_webpdf_with_nbconvert` left it green. Drive `_render_webpdf_with_nbconvert` directly and stub `WebPDFExporter.run_playwright`, which receives the fully rendered HTML, so the assertion covers the real registration without needing Chromium.
1 parent 65ea58f commit c8a212a

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

tests/_server/export/test_exporter.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,12 +1666,11 @@ def test_webpdf_inlines_code_wrapping_css(self) -> None:
16661666
Regression test for marimo-team/marimo#9421.
16671667
"""
16681668
import nbformat
1669-
from nbconvert import HTMLExporter
1669+
from nbconvert import WebPDFExporter
16701670

16711671
from marimo._server.export.exporter import (
16721672
WEBPDF_CODE_WRAP_CSS,
1673-
_inline_code_wrap_css,
1674-
_nbconvert_tag_remove_config,
1673+
_render_webpdf_with_nbconvert,
16751674
)
16761675

16771676
notebook = nbformat.v4.new_notebook()
@@ -1682,21 +1681,29 @@ def test_webpdf_inlines_code_wrapping_css(self) -> None:
16821681
)
16831682
]
16841683

1685-
# WebPDFExporter renders through the `webpdf` template; asserting on
1686-
# the HTML avoids needing Chromium in CI.
1687-
exporter = HTMLExporter(
1688-
config=_nbconvert_tag_remove_config(), template_name="webpdf"
1689-
)
1690-
rendered_without, _ = exporter.from_notebook_node(notebook)
1691-
assert WEBPDF_CODE_WRAP_CSS not in rendered_without
1684+
# `run_playwright` receives the fully rendered HTML, so stubbing it
1685+
# captures what Chromium would have been handed without needing a
1686+
# browser. Going through `_render_webpdf_with_nbconvert` means the
1687+
# test fails if the production code stops registering the
1688+
# preprocessor.
1689+
rendered: list[str] = []
16921690

1693-
exporter.register_preprocessor(_inline_code_wrap_css, enabled=True)
1694-
rendered, _ = exporter.from_notebook_node(notebook)
1691+
def fake_run_playwright(self: Any, html: str) -> bytes:
1692+
del self
1693+
rendered.append(html)
1694+
return b"mock_pdf_data"
1695+
1696+
with patch.object(
1697+
WebPDFExporter, "run_playwright", fake_run_playwright
1698+
):
1699+
pdf_data = _render_webpdf_with_nbconvert(
1700+
notebook, include_inputs=True
1701+
)
16951702

1696-
# The stylesheet must actually reach the document: a misresolved
1697-
# template or preprocessor fails silently, leaving the bug in place.
1698-
assert WEBPDF_CODE_WRAP_CSS in rendered
1699-
assert "white-space: pre-wrap !important" in rendered
1703+
assert pdf_data == b"mock_pdf_data"
1704+
assert len(rendered) == 1
1705+
assert WEBPDF_CODE_WRAP_CSS in rendered[0]
1706+
assert "white-space: pre-wrap !important" in rendered[0]
17001707

17011708
@pytest.mark.asyncio
17021709
async def test_run_app_then_export_as_pdf_ignores_status_callback_failures(

0 commit comments

Comments
 (0)