Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7457eda

Browse files
authored
Merge pull request #11427 from jklymak/fix-pathlib-nbagg
FIX: pathlib in nbagg
2 parents 7b96f00 + e8ab1b0 commit 7457eda

File tree

4 files changed

+922
-1
lines changed

4 files changed

+922
-1
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ env:
5454
- NOSE=
5555
- NUMPY=numpy
5656
- PANDAS=
57+
- JUPYTER=
5758
- PYPARSING=pyparsing
5859
- PYTEST='pytest>=3.4'
5960
- PYTEST_COV=pytest-cov
@@ -94,6 +95,7 @@ matrix:
9495
env:
9596
- DELETE_FONT_CACHE=1
9697
- PANDAS='pandas<0.21.0'
98+
- JUPYTER='jupyter'
9799
- PYTEST_PEP8=pytest-pep8
98100
- PYTEST_ADDOPTS="$PYTEST_ADDOPTS --pep8"
99101
- python: "nightly"
@@ -147,6 +149,7 @@ install:
147149
$NOSE \
148150
$NUMPY \
149151
$PANDAS \
152+
$JUPYTER \
150153
pillow \
151154
$PYPARSING \
152155
$SPHINX \

lib/matplotlib/backends/backend_nbagg.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io
88
import json
99
import os
10+
import pathlib
1011
import uuid
1112

1213
from IPython.display import display, Javascript, HTML
@@ -111,7 +112,8 @@ def get_javascript(cls, stream=None):
111112
else:
112113
output = stream
113114
super().get_javascript(stream=output)
114-
output.write((Path(__file__).parent / "web_backend/js/nbagg_mpl.js")
115+
output.write((pathlib.Path(__file__).parent
116+
/ "web_backend/js/nbagg_mpl.js")
115117
.read_text(encoding="utf-8"))
116118
if stream is None:
117119
return output.getvalue()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
import os
3+
import subprocess
4+
import tempfile
5+
import pytest
6+
7+
nbformat = pytest.importorskip('nbformat')
8+
9+
# From https://blog.thedataincubator.com/2016/06/testing-jupyter-notebooks/
10+
11+
12+
def _notebook_run(nb_file):
13+
"""Execute a notebook via nbconvert and collect output.
14+
:returns (parsed nb object, execution errors)
15+
"""
16+
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
17+
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
18+
"--ExecutePreprocessor.timeout=500",
19+
"--output", fout.name, nb_file]
20+
subprocess.check_call(args)
21+
22+
fout.seek(0)
23+
nb = nbformat.read(fout, nbformat.current_nbformat)
24+
25+
errors = [output for cell in nb.cells if "outputs" in cell
26+
for output in cell["outputs"]
27+
if output.output_type == "error"]
28+
return nb, errors
29+
30+
31+
def test_ipynb():
32+
nb, errors = _notebook_run('lib/matplotlib/tests/test_nbagg_01.ipynb')
33+
assert errors == []

0 commit comments

Comments
 (0)