Skip to content

Commit 668fc03

Browse files
committed
Merge branch 'release' into barnhark/rockblock
2 parents 1ccdc22 + 1e5cf0a commit 668fc03

2 files changed

Lines changed: 28 additions & 33 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ install:
5353
- conda install --file=requirements.txt
5454
- conda info -a && conda list
5555
script:
56+
- mkdir -p $HOME/.config/matplotlib # For Python 3.5
5657
- travis_wait 50 pytest -vvv # the cellular atomata test takes over 10 minutes, and the entire process takes about 30 minutes, so we'll give it 50 min
5758
virtualenv:
5859
system_site_packages: false

test_notebooks.py

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,53 @@
11
import os
22
import subprocess
3+
import tempfile
34

45
import nbformat
5-
import pytest
6-
76

87
_TEST_DIR = os.path.abspath(os.path.dirname(__file__))
98
_EXCLUDE = ["Python_intro.ipynb", "animate-landlab-output.ipynb"]
109

1110

12-
def all_notebooks():
11+
def all_notebooks(path="."):
1312
notebooks = []
14-
for root, dirs, files in os.walk(_TEST_DIR):
13+
for root, dirs, files in os.walk(path):
14+
if ".ipynb_checkpoints" in root:
15+
continue
1516
for file in files:
16-
if (
17-
file.endswith(".ipynb")
18-
and (file not in _EXCLUDE)
19-
and ("checkpoint" not in file)
20-
):
17+
if file.endswith(".ipynb") and (file not in _EXCLUDE):
2118
notebooks.append(os.path.join(root, file))
2219
return notebooks
2320

2421

2522
def pytest_generate_tests(metafunc):
2623
if "notebook" in metafunc.fixturenames:
27-
metafunc.parametrize("notebook", all_notebooks())
24+
metafunc.parametrize("notebook", all_notebooks(_TEST_DIR))
2825

2926

3027
def _notebook_run(path):
3128
"""Execute a notebook via nbconvert and collect output.
3229
:returns (parsed nb object, execution errors)
3330
"""
34-
dirname, __ = os.path.split(path)
35-
os.chdir(dirname)
36-
37-
in_fn = os.path.split(path)[-1].split(".")[0]
38-
temp_file_prefix = "output_" + in_fn
39-
temp_file_out = temp_file_prefix + ".ipynb"
40-
41-
args = [
42-
"jupyter",
43-
"nbconvert",
44-
"--to",
45-
"notebook",
46-
"--execute",
47-
"--ExecutePreprocessor.kernel_name=python",
48-
"--ExecutePreprocessor.timeout=None",
49-
"--output",
50-
temp_file_prefix,
51-
path,
52-
]
53-
subprocess.check_call(args)
54-
55-
nb = nbformat.read(temp_file_out, nbformat.current_nbformat, encoding="UTF-8")
31+
_, notebook = os.path.split(path)
32+
base, ext = os.path.splitext(notebook)
33+
34+
with tempfile.NamedTemporaryFile("w", suffix=".ipynb") as fp:
35+
args = [
36+
"jupyter",
37+
"nbconvert",
38+
"--to",
39+
"notebook",
40+
"--execute",
41+
"--ExecutePreprocessor.kernel_name=python",
42+
"--ExecutePreprocessor.timeout=None",
43+
"--output",
44+
fp.name,
45+
"--output-dir=.",
46+
path,
47+
]
48+
subprocess.check_call(args)
49+
50+
nb = nbformat.read(fp.name, nbformat.current_nbformat, encoding="UTF-8")
5651

5752
errors = [
5853
output
@@ -61,7 +56,6 @@ def _notebook_run(path):
6156
for output in cell["outputs"]
6257
if output.output_type == "error"
6358
]
64-
os.remove(temp_file_out)
6559

6660
return nb, errors
6761

0 commit comments

Comments
 (0)