Skip to content

Commit 4fc796c

Browse files
committed
Reactivate jupyter test
1 parent 84ef72d commit 4fc796c

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

example/test_examples.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,32 @@ def test_basic_example_flh(self):
1818
assert_allclose(1766.6870, (e126.power_output.sum() /
1919
e126.nominal_power), 0.01)
2020
assert_allclose(1882.7567, (my_turbine.power_output.sum() /
21-
my_turbine.nominal_power), 0.01)
22-
#
23-
# def _notebook_run(self, path):
24-
# """
25-
# Execute a notebook via nbconvert and collect output.
26-
# Returns (parsed nb object, execution errors)
27-
# """
28-
# dirname, __ = os.path.split(path)
29-
# os.chdir(dirname)
30-
# with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
31-
# args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
32-
# "--ExecutePreprocessor.timeout=60",
33-
# "--output", fout.name, path]
34-
# subprocess.check_call(args)
35-
#
36-
# fout.seek(0)
37-
# nb = nbformat.read(fout, nbformat.current_nbformat)
38-
#
39-
# errors = [output for cell in nb.cells if "outputs" in cell
40-
# for output in cell["outputs"]
41-
# if output.output_type == "error"]
42-
#
43-
# return nb, errors
44-
#
45-
# def test_basic_example_ipynb(self):
46-
# dir_path = os.path.dirname(os.path.realpath(__file__))
47-
# nb, errors = self._notebook_run(os.path.join(dir_path,
48-
# 'basic_example.ipynb'))
49-
# assert errors == []
21+
my_turbine.nominal_power), 0.01)
22+
23+
def _notebook_run(self, path):
24+
"""
25+
Execute a notebook via nbconvert and collect output.
26+
Returns (parsed nb object, execution errors)
27+
"""
28+
dirname, __ = os.path.split(path)
29+
os.chdir(dirname)
30+
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
31+
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
32+
"--ExecutePreprocessor.timeout=60",
33+
"--output", fout.name, path]
34+
subprocess.check_call(args)
35+
36+
fout.seek(0)
37+
nb = nbformat.read(fout, nbformat.current_nbformat)
38+
39+
errors = [output for cell in nb.cells if "outputs" in cell
40+
for output in cell["outputs"]
41+
if output.output_type == "error"]
42+
43+
return nb, errors
44+
45+
def test_basic_example_ipynb(self):
46+
dir_path = os.path.dirname(os.path.realpath(__file__))
47+
nb, errors = self._notebook_run(os.path.join(dir_path,
48+
'basic_example.ipynb'))
49+
assert errors == []

0 commit comments

Comments
 (0)