Tests#
$ uv run pytest # everything
$ uv run pytest tests/test_latex_renderer.py -q
$ uv run pytest --cov=handcalcs # with coverage
Layout#
Files |
Cover |
|---|---|
|
Source → node tree, and the post-parse passes |
|
Node classes |
|
|
|
Each renderer, through the full pipeline |
|
The interfaces |
|
Configuration |
tests/conftest.py provides renderer (a fresh BaseRenderer) and make_context (a
BaseRenderContext factory) for rendering a single hand-built node in isolation, so node
tests don’t depend on the parser.
Golden files#
The LaTeX and Markdown renderers are tested against tests/golden/latex_demo.tex and
tests/golden/markdown_demo.md: the rendered demo, compared section by section. After an
intended change to the output, regenerate and review:
$ HANDCALCS_UPDATE_GOLDEN=1 uv run pytest tests/test_latex_renderer.py tests/test_markdown_renderer.py
$ git diff tests/golden
Optional checks#
Some tests are skipped unless a tool is available:
LaTeX compile:
test_latex_renderer.pycompiles the demo withpdflatexif it is installed.scripts/latex_demo_check.pydoes the same by hand and reports overfull boxes.KaTeX:
test_markdown_renderer.pytypesets every math fragment with KaTeX whenHANDCALCS_KATEX_JSpoints tokatex.min.jsandmini-raceris installed:$ HANDCALCS_KATEX_JS=katex.min.js uv run --with mini-racer pytest tests/test_markdown_renderer.pyExcel recalculation:
scripts/excel_demo.pywrites the Excel demo; run it withuv run --with formulasto recalculate every formula independently and compare it with Python.
Configuration in tests#
Tests that touch configuration point HANDCALCS_CONFIG at a temporary file and reset
the in-memory config (see the isolated_config fixture in test_jupyter.py), so a
developer’s own saved config never affects results.
The docs as tests#
Every hc-example block in these docs runs handcalcs when the docs are built, and a
failure stops the build with the exception. Building the docs is therefore a check on the
examples (see Documentation).