-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
Update testing procedures
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,9 @@ | |
|
||
*.out | ||
*.pyc | ||
|
||
\.pytest_cache/README\.md | ||
|
||
\.pytest_cache/v/cache/lastfailed | ||
|
||
\.pytest_cache/v/cache/nodeids |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
This file was deleted.
This file was deleted.
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
jupyter | ||
dask | ||
holoviews | ||
pytest |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import os | ||
import subprocess | ||
import tempfile | ||
|
||
import nbformat | ||
|
||
_TEST_DIR = os.path.abspath(os.path.dirname(__file__)) | ||
_EXCLUDE = ["Python_intro.ipynb", "animate-landlab-output.ipynb"] | ||
|
||
|
||
def all_notebooks(path="."): | ||
notebooks = [] | ||
for root, dirs, files in os.walk(path): | ||
if ".ipynb_checkpoints" in root: | ||
continue | ||
for file in files: | ||
if file.endswith(".ipynb") and (file not in _EXCLUDE): | ||
notebooks.append(os.path.join(root, file)) | ||
return notebooks | ||
|
||
|
||
def pytest_generate_tests(metafunc): | ||
if "notebook" in metafunc.fixturenames: | ||
metafunc.parametrize("notebook", all_notebooks(_TEST_DIR)) | ||
|
||
|
||
def _notebook_run(path): | ||
"""Execute a notebook via nbconvert and collect output. | ||
:returns (parsed nb object, execution errors) | ||
""" | ||
_, notebook = os.path.split(path) | ||
base, ext = os.path.splitext(notebook) | ||
|
||
with tempfile.NamedTemporaryFile("w", suffix=".ipynb") as fp: | ||
args = [ | ||
"jupyter", | ||
"nbconvert", | ||
"--to", | ||
"notebook", | ||
"--execute", | ||
"--ExecutePreprocessor.kernel_name=python", | ||
"--ExecutePreprocessor.timeout=None", | ||
"--output", | ||
fp.name, | ||
"--output-dir=.", | ||
path, | ||
] | ||
subprocess.check_call(args) | ||
|
||
nb = nbformat.read(fp.name, nbformat.current_nbformat, encoding="UTF-8") | ||
|
||
errors = [ | ||
output | ||
for cell in nb.cells | ||
if "outputs" in cell | ||
for output in cell["outputs"] | ||
if output.output_type == "error" | ||
] | ||
|
||
return nb, errors | ||
|
||
|
||
def test_notebook(tmpdir, notebook): | ||
with tmpdir.as_cwd(): | ||
nb, errors = _notebook_run(notebook) | ||
assert not errors |