Skip to content

Commit 5f418bc

Browse files
committed
Use pytest-notebook again to avoid Permission denied error on windows
1 parent edc6862 commit 5f418bc

File tree

3 files changed

+17
-39
lines changed

3 files changed

+17
-39
lines changed

example/test_examples.py

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
"""
55

66
import os
7-
import subprocess
8-
import tempfile
9-
import nbformat
107
from example import modelchain_example as mc_e
118
from example import turbine_cluster_modelchain_example as tc_mc_e
129
from numpy.testing import assert_allclose
10+
import pytest_notebook
1311

1412

1513
class TestExamples:
@@ -55,48 +53,27 @@ def test_turbine_cluster_modelchain_example_flh(self):
5553

5654
def _notebook_run(self, path):
5755
"""
58-
Execute a notebook via nbconvert and collect output.
59-
Returns (parsed nb object, execution errors)
56+
Execute a notebook and collect output.
57+
Returns execution errors.
6058
"""
61-
dirname, __ = os.path.split(path)
62-
os.chdir(dirname)
63-
with tempfile.NamedTemporaryFile(suffix=".ipynb", dir=dirname) as fout:
64-
args = [
65-
"jupyter",
66-
"nbconvert",
67-
"--to",
68-
"notebook",
69-
"--execute",
70-
"--ExecutePreprocessor.timeout=600",
71-
"--output",
72-
fout.name,
73-
path,
74-
]
75-
subprocess.check_call(args)
76-
77-
fout.seek(0)
78-
nb = nbformat.read(fout, nbformat.current_nbformat)
79-
80-
errors = [
81-
output
82-
for cell in nb.cells
83-
if "outputs" in cell
84-
for output in cell["outputs"]
85-
if output.output_type == "error"
86-
]
87-
88-
return nb, errors
59+
notebook = pytest_notebook.notebook.load_notebook(path=path)
60+
result = pytest_notebook.execution.execute_notebook(
61+
notebook,
62+
with_coverage=False,
63+
timeout=600,
64+
)
65+
return result.exec_error
8966

9067
def test_modelchain_example_ipynb(self):
9168
dir_path = os.path.dirname(os.path.realpath(__file__))
92-
nb, errors = self._notebook_run(
69+
errors = self._notebook_run(
9370
os.path.join(dir_path, "modelchain_example.ipynb")
9471
)
95-
assert errors == []
72+
assert errors is None
9673

9774
def test_turbine_cluster_modelchain_example_ipynb(self):
9875
dir_path = os.path.dirname(os.path.realpath(__file__))
99-
nb, errors = self._notebook_run(
76+
errors = self._notebook_run(
10077
os.path.join(dir_path, "turbine_cluster_modelchain_example.ipynb")
10178
)
102-
assert errors == []
79+
assert errors is None

example/turbine_cluster_modelchain_example.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"source": [
4242
"import os\n",
4343
"import pandas as pd\n",
44+
"import requests\n",
4445
"\n",
4546
"from windpowerlib import create_power_curve, TurbineClusterModelChain, WindFarm, WindTurbine, WindTurbineCluster\n",
4647
"\n",

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ def read(fname):
2424
long_description=read("README.rst"),
2525
long_description_content_type="text/x-rst",
2626
zip_safe=False,
27-
install_requires=["pandas >= 0.20.0", "requests"],
27+
install_requires=["pandas >= 0.20.0", "requests"], # check
2828
extras_require={
2929
"dev": [
3030
"pytest",
3131
"jupyter",
3232
"sphinx_rtd_theme",
33-
"nbformat",
3433
"numpy",
3534
"matplotlib",
35+
"pytest-notebook",
3636
]
3737
},
3838
)

0 commit comments

Comments
 (0)