Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7e56deb

Browse filesBrowse files
committed
TST: add test for notebook executing
1 parent 14eadeb commit 7e56deb
Copy full SHA for 7e56deb

File tree

Expand file treeCollapse file tree

2 files changed

+914
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+914
-0
lines changed
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
import os
3+
import subprocess
4+
import tempfile
5+
import nbformat
6+
7+
8+
# From https://blog.thedataincubator.com/2016/06/testing-jupyter-notebooks/
9+
10+
def _notebook_run(nb_file):
11+
"""Execute a notebook via nbconvert and collect output.
12+
:returns (parsed nb object, execution errors)
13+
"""
14+
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
15+
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
16+
"--ExecutePreprocessor.timeout=500",
17+
"--output", fout.name, nb_file]
18+
subprocess.check_call(args)
19+
20+
fout.seek(0)
21+
nb = nbformat.read(fout, nbformat.current_nbformat)
22+
23+
errors = [output for cell in nb.cells if "outputs" in cell
24+
for output in cell["outputs"]
25+
if output.output_type == "error"]
26+
return nb, errors
27+
28+
29+
def test_ipynb():
30+
nb, errors = _notebook_run('lib/matplotlib/tests/test_nbagg_01.ipynb')
31+
assert errors == []

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.