Skip to content

Isolate nbagg test from user ipython profile. #14157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions lib/matplotlib/tests/test_backend_nbagg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from pathlib import Path
import subprocess
import tempfile
from tempfile import TemporaryDirectory

import pytest

Expand All @@ -9,25 +10,20 @@
# From https://blog.thedataincubator.com/2016/06/testing-jupyter-notebooks/


def _notebook_run(nb_file):
"""Execute a notebook via nbconvert and collect output.
:returns (parsed nb object, execution errors)
"""
with tempfile.NamedTemporaryFile(suffix=".ipynb", mode='w+t') as fout:
subprocess.check_call([
"jupyter", "nbconvert", "--to", "notebook",
"--execute", "--ExecutePreprocessor.timeout=500",
"--output", fout.name, nb_file,
])
fout.seek(0)
nb = nbformat.read(fout, nbformat.current_nbformat)
def test_ipynb():
nb_path = Path(__file__).parent / 'test_nbagg_01.ipynb'

with TemporaryDirectory() as tmpdir:
out_path = Path(tmpdir, "out.ipynb")
subprocess.check_call(
["jupyter", "nbconvert", "--to", "notebook",
"--execute", "--ExecutePreprocessor.timeout=500",
"--output", str(out_path), str(nb_path)],
env={**os.environ, "IPYTHONDIR": tmpdir})
with out_path.open() as out:
nb = nbformat.read(out, nbformat.current_nbformat)

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_ipynb():
nb, errors = _notebook_run(Path(__file__).parent / 'test_nbagg_01.ipynb')
assert errors == []
assert not errors