-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6258ebd
commit 6a2d644
Showing
1 changed file
with
5 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,22 @@ | ||
import os | ||
import shutil | ||
import pytest | ||
import nbformat | ||
from nbconvert.preprocessors import ExecutePreprocessor | ||
|
||
TEST_TMPDIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", ".cache") | ||
|
||
|
||
# ########################## | ||
# Tests setup function | ||
# ########################## | ||
def setup_function(): | ||
if not os.path.exists(TEST_TMPDIR): | ||
os.mkdir(TEST_TMPDIR) | ||
|
||
|
||
# ########################## | ||
# Tests executing the notebook | ||
# ########################## | ||
def test_notebook(): | ||
def test_notebook(tmpdir): | ||
"""Test the notebook.""" | ||
tmp = tmpdir.mkdir('sub') | ||
# Open the notebook | ||
with open("index.ipynb", "r") as f: | ||
nb = nbformat.read(f, as_version=4) | ||
|
||
# Process the notebook | ||
ep = ExecutePreprocessor(timeout=600, kernel_name="python3") | ||
ep.preprocess(nb, {"metadata": {"path": TEST_TMPDIR}}) | ||
ep.preprocess(nb, {"metadata": {"path": os.getcwd()}}) | ||
|
||
# Save the executed notebook | ||
out_nb = os.path.join(TEST_TMPDIR, "executed_notebook.ipynb") | ||
out_nb = os.path.join(tmp, "executed_notebook.ipynb") | ||
with open(out_nb, "w", encoding="utf-8") as f: | ||
nbformat.write(nb, f) | ||
|
||
assert os.path.exists(out_nb) | ||
|
||
|
||
# ############################## | ||
# Clean up test files | ||
# ############################## | ||
def teardown_function(): | ||
shutil.rmtree(TEST_TMPDIR) |