Skip to content

Commit

Permalink
Update tests.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkenney42 authored Nov 12, 2024
1 parent 6258ebd commit 6a2d644
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions tests/tests.py
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)

0 comments on commit 6a2d644

Please sign in to comment.