Skip to content

Commit 1b9b64d

Browse files
authored
Merge pull request #5 from marimo-team/aka/smoke-tests
tests: test notebooks for syntax errors
2 parents 994c0fc + 2722921 commit 1b9b64d

File tree

6 files changed

+52
-31
lines changed

6 files changed

+52
-31
lines changed

.github/workflows/test.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request: {}
7+
8+
jobs:
9+
test:
10+
name: Test notebooks
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: 🛑 Cancel Previous Runs
14+
uses: styfle/[email protected]
15+
- name: Checkout the repository
16+
uses: actions/checkout@main
17+
- name: 🐍 Setup uv
18+
uses: astral-sh/setup-uv@v5
19+
- name: Run tests
20+
run: |
21+
uvx --with marimo pytest -v

.github/workflows/test_typos.yaml

-15
This file was deleted.

.pre-commit-config.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ repos:
2222
rev: dictgen-v0.3.1
2323
hooks:
2424
- id: typos
25+
26+
- repo: https://github.com/astral-sh/ruff-pre-commit
27+
rev: v0.9.1
28+
hooks:
29+
# Run the formatter
30+
- id: ruff-format
31+

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ and apps.
1313

1414
## Running examples
1515

16-
Each example has a README that tells you how to run it locally.
17-
18-
Most examples can also be opened in marimo's [online
16+
Each example has a README that tells you how to run it locally. Most examples
17+
can also be opened in marimo's [online
1918
playground](https://docs.marimo.io/guides/publishing/playground/) by clicking
2019
the "open in marimo" badge in its README.
2120

@@ -25,7 +24,8 @@ We welcome community contributions of examples; you don't need to be
2524
an expert to help out!
2625

2726
Open a pull request to contribute a new example. Each example should be placed
28-
in its own folder and include a short `README.md`.
27+
in its own folder and include a short `README.md`. We also include smoke tests
28+
for each notebook in `tests/`. Run tests with `uvx --with marimo pytest .`
2929

3030
Looking for a specific example or template but can't find it? Feel free
3131
to file an issue and request it!

nlp_span_comparison/nlp_span_comparison.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ def _(annotate, mo):
9494

9595
@app.cell
9696
def _(CHOICES_PATH, PARAGRAPHS, load_choices, mo):
97-
get_choices, set_choices = mo.state(
98-
load_choices(CHOICES_PATH, len(PARAGRAPHS))
99-
)
97+
get_choices, set_choices = mo.state(load_choices(CHOICES_PATH, len(PARAGRAPHS)))
10098
return get_choices, set_choices
10199

102100

@@ -137,9 +135,7 @@ def _(PARAGRAPHS, SPANS, annotate, index, mo):
137135

138136
@app.cell
139137
def _(mo, model_A_prediction, model_B_prediction):
140-
mo.hstack(
141-
[model_A_prediction, model_B_prediction], gap=2, justify="space-around"
142-
)
138+
mo.hstack([model_A_prediction, model_B_prediction], gap=2, justify="space-around")
143139
return
144140

145141

@@ -169,19 +165,18 @@ def load_choices(path, number_of_examples):
169165
assert len(choices) == number_of_examples
170166
return choices
171167

172-
173168
def write_choices(choices, path):
174169
# Trunacate notes
175170
with open(path, "w") as f:
176171
f.write(json.dumps(choices))
172+
177173
return load_choices, write_choices
178174

179175

180176
@app.cell
181177
def _(PARAGRAPHS, random):
182178
random.seed(0)
183179

184-
185180
def predict_spans(text):
186181
first = [random.randint(0, len(text) - 2)]
187182
first.append(random.randint(first[0] + 1, len(text) - 1))
@@ -190,17 +185,14 @@ def predict_spans(text):
190185

191186
return first, second
192187

193-
194188
SPANS = [predict_spans(p) for p in PARAGRAPHS]
195189
return SPANS, predict_spans
196190

197191

198192
@app.cell
199193
def _(HAMLET, textwrap):
200194
PARAGRAPHS = [
201-
textwrap.dedent(block).strip()[:1000]
202-
for block in HAMLET.split("\n\n")
203-
if block
195+
textwrap.dedent(block).strip()[:1000] for block in HAMLET.split("\n\n") if block
204196
]
205197
return (PARAGRAPHS,)
206198

@@ -216,6 +208,7 @@ def annotate(text, span, color):
216208
+ "</mark>"
217209
+ text[span[1] :]
218210
)
211+
219212
return (annotate,)
220213

221214

@@ -237,6 +230,7 @@ def _(urllib):
237230
@app.cell
238231
def _():
239232
import marimo as mo
233+
240234
return (mo,)
241235

242236

@@ -247,6 +241,7 @@ def _():
247241
import random
248242
import textwrap
249243
import urllib
244+
250245
return json, os, random, textwrap, urllib
251246

252247

tests/test_examples_without_error.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Smoke tests that check notebooks don't have syntax errors."""
2+
3+
import pathlib
4+
import sys
5+
6+
ROOT = pathlib.Path(__file__).parent.parent
7+
sys.path.append(str(ROOT))
8+
9+
10+
def test_nlp_span_comparison() -> None:
11+
from nlp_span_comparison import nlp_span_comparison
12+
13+
assert not nlp_span_comparison.app._unparsable

0 commit comments

Comments
 (0)