Skip to content

Commit bbc7876

Browse files
committed
Modified test_notebooks
1 parent b708082 commit bbc7876

1 file changed

Lines changed: 17 additions & 32 deletions

File tree

binder/test_notebooks.py

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,32 @@
22

33
import sys
44
import subprocess
5-
import tempfile
65
import nbformat
76

87
from os import listdir
9-
from os.path import isfile, join, isdir
8+
from os.path import isfile, join
109

1110

12-
def notebook_run(path):
13-
"""Execute a notebook via nbconvert and collect output.
14-
:returns (parsed nb object, execution errors)
15-
"""
16-
17-
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
18-
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
19-
"--ExecutePreprocessor.timeout=600",
20-
"--output", fout.name, path]
21-
subprocess.check_call(args)
22-
23-
fout.seek(0)
24-
nb = nbformat.read(fout.name, nbformat.current_nbformat)
25-
26-
errors = [output for cell in nb.cells if "outputs" in cell
27-
for output in cell["outputs"]\
28-
if output.output_type == "error"]
29-
30-
return nb, errors
11+
def test_notebooks(path):
3112

13+
notebooks = [
14+
f for f in listdir(path) if isfile(join(path, f)) and f.endswith(".ipynb")
15+
]
3216

33-
def test_notebooks(path):
34-
35-
notebooks = [f for f in listdir(path) if isfile(join(path, f)) and f.endswith('.ipynb') and f!='test_notebooks']
36-
directories = [f for f in listdir(path) if isdir(join(path, f))]
37-
3817
for notebook in sorted(notebooks):
3918
print(notebook)
40-
_, errors = notebook_run(join(path, notebook))
41-
if errors != []:
19+
args = [
20+
"jupyter",
21+
"nbconvert",
22+
"--to",
23+
"notebook",
24+
"--execute",
25+
"--ExecutePreprocessor.timeout=600",
26+
join(path, notebook),
27+
]
28+
exit_code = subprocess.check_call(args)
29+
if exit_code != 0:
4230
raise AssertionError
43-
44-
for directory in sorted(directories):
45-
print(directory)
4631

4732

4833
def main():
@@ -51,4 +36,4 @@ def main():
5136

5237

5338
if __name__ == "__main__":
54-
main()
39+
main()

0 commit comments

Comments
 (0)