-
Notifications
You must be signed in to change notification settings - Fork 118
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
Showing
6 changed files
with
78 additions
and
1 deletion.
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
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
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 |
---|---|---|
|
@@ -31,3 +31,4 @@ xlrd==2.0.1 | |
openpyxl==3.0.6 | ||
smart-open==4.1.2 | ||
tqdm==4.54.0 | ||
nbconvert==6.0.7 |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import os | ||
import sys | ||
import pytest | ||
_MY_DIR = os.path.realpath(os.path.dirname(__file__)) | ||
# Allow import of the test utilities packages | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def notebooks_path(): | ||
|
||
notebook_path = os.path.join( | ||
_MY_DIR, os.pardir, os.pardir, "notebooks") | ||
return os.path.abs(notebook_path) |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from nbconvert.preprocessors import CellExecutionError | ||
from nbconvert.preprocessors import ExecutePreprocessor | ||
import nbformat | ||
import subprocess | ||
import os | ||
import pytest | ||
|
||
TEST_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
PARENT_DIR = os.path.join(TEST_DIR, os.pardir, "..") | ||
|
||
|
||
def process_notebook(notebook_filename, html_directory="notebook-html"): | ||
"""Checks if an IPython notebook runs without error from start to finish. If so, writes the notebook to HTML (with outputs) and overwrites the .ipynb file (without outputs).""" | ||
|
||
with open(notebook_filename) as f: | ||
nb = nbformat.read(f, as_version=4) | ||
|
||
ep = ExecutePreprocessor(timeout=600, kernel_name="python3", allow_errors=True) | ||
|
||
try: | ||
# Check that the notebook runs | ||
ep.preprocess(nb, {"metadata": {"path": ""}}) | ||
except CellExecutionError: | ||
raise | ||
|
||
print(f"Successfully executed {notebook_filename}") | ||
return | ||
|
||
|
||
def test_all_notebooks(remove_fail_test=True): | ||
""" | ||
Runs `process_notebook` on all notebooks in the git repository. | ||
""" | ||
|
||
# Get all files included in the git repository | ||
git_files = subprocess.check_output("git ls-tree --full-tree --name-only -r HEAD", shell=True).decode("utf-8").splitlines() | ||
|
||
# Get just the notebooks from the git files | ||
notebooks = [fn for fn in git_files if fn.endswith(".ipynb")] | ||
print(notebooks) | ||
|
||
# Test each notebook | ||
for notebook in notebooks: | ||
print("Testing", notebook) | ||
process_notebook(os.path.join(PARENT_DIR, notebook)) | ||
|
||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
test_all_notebooks() |