Skip to content

Commit a0b9e0a

Browse files
authored
feat: pdf export visual snapshot testing (#29)
1 parent e645cc9 commit a0b9e0a

28 files changed

+794
-144
lines changed

.github/workflows/export-notebooks.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,31 @@ jobs:
4343
- name: 📄 Install system dependencies (LaTeX and Pandoc)
4444
run: |
4545
sudo apt-get update
46-
sudo apt-get install -y texlive-xetex texlive-fonts-recommended texlive-plain-generic pandoc
46+
sudo apt-get install -y texlive-xetex texlive-fonts-recommended texlive-plain-generic pandoc poppler-utils
4747
continue-on-error: true
4848

4949
- name: 📦 Install Python dependencies
5050
run: |
5151
uv sync --extra pdf
5252
53+
- name: 🎭 Install Chromium (for WebPDF)
54+
run: |
55+
uv run python -m playwright install --with-deps chromium
56+
57+
- name: 🖼️ PDF visual snapshot test
58+
id: pdf_snapshot
59+
run: |
60+
uv run scripts/test_pdf_visual_snapshots.py
61+
62+
- name: 📦 Upload PDF snapshot artifacts (on failure)
63+
if: failure() && steps.pdf_snapshot.outcome == 'failure'
64+
uses: actions/upload-artifact@v6
65+
with:
66+
name: pdf-visual-snapshot-artifacts
67+
path: snapshot_artifacts/
68+
if-no-files-found: ignore
69+
retention-days: 7
70+
5371
- name: 📂 Setup examples
5472
run: |
5573
uv run scripts/setup_examples.py

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# marimo
22
/examples
33

4+
# Snapshot artifacts (generated locally / uploaded in CI on failure)
5+
/snapshot_artifacts/
6+
47
# Byte-compiled / optimized / DLL files
58
__pycache__/
69
*.py[cod]

notebooks/pdf_snapshot_smoke.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "marimo",
5+
# "matplotlib",
6+
# ]
7+
# ///
8+
9+
import marimo
10+
11+
__generated_with = "0.19.7"
12+
app = marimo.App(width="medium")
13+
14+
with app.setup:
15+
import marimo as mo
16+
17+
18+
@app.cell(hide_code=True)
19+
def _():
20+
import matplotlib as mpl
21+
mpl.use("Agg")
22+
23+
import matplotlib.pyplot as plt
24+
25+
plt.rcParams.update(
26+
{
27+
# Keeping this small so that the PDF fits on a single page.
28+
"figure.figsize": (2.6, 1.4),
29+
"figure.dpi": 150,
30+
}
31+
)
32+
33+
x = [1, 2, 3]
34+
y = [1, 4, 9]
35+
36+
fig, ax = plt.subplots()
37+
ax.plot(x, y, marker="o")
38+
ax.set_title("y=x^2")
39+
fig.tight_layout()
40+
fig
41+
return
42+
43+
44+
if __name__ == "__main__":
45+
app.run()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies = [
1313
"matplotlib",
1414
"pandas",
1515
"nbconvert",
16+
"pillow",
1617
]
1718

1819
[project.optional-dependencies]

0 commit comments

Comments
 (0)