Skip to content

Commit b53dae8

Browse files
committed
removing use of temporary file and explicitly stating encodign
this works for local testing in py3.5 and py3.6 envs
1 parent 5882a21 commit b53dae8

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

test_notebooks.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import os
2-
3-
42
import subprocess
5-
import tempfile
6-
73
import nbformat
84

95
_TEST_DIR = os.path.dirname(__file__)
@@ -16,19 +12,23 @@ def _notebook_run(path):
1612
"""
1713
dirname, __ = os.path.split(path)
1814
os.chdir(dirname)
19-
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
20-
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
21-
"--ExecutePreprocessor.kernel_name=python",
22-
"--ExecutePreprocessor.timeout=None",
23-
"--output", fout.name, path]
24-
subprocess.check_call(args)
2515

26-
fout.seek(0)
27-
nb = nbformat.read(fout, nbformat.current_nbformat)
16+
in_fn = os.path.split(path)[-1].split('.')[0]
17+
temp_file_prefix = 'output_' + in_fn
18+
temp_file_out = temp_file_prefix + '.ipynb'
19+
20+
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
21+
"--ExecutePreprocessor.kernel_name=python",
22+
"--ExecutePreprocessor.timeout=None",
23+
"--output", temp_file_prefix, path]
24+
subprocess.check_call(args)
25+
26+
nb = nbformat.read(temp_file_out, nbformat.current_nbformat, encoding='UTF-8')
2827

2928
errors = [output for cell in nb.cells if "outputs" in cell
3029
for output in cell["outputs"]\
3130
if output.output_type == "error"]
31+
os.remove(temp_file_out)
3232

3333
return nb, errors
3434

0 commit comments

Comments
 (0)