Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/test_notebooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#%%
# depenencies
from pathlib import Path
import papermill as pm
import pytest

#%%
# paths
CWD = Path(__file__).parent.resolve()
BASE_DIR = CWD.parent.parent

#%%
# Collect all notebooks you want to test
notebooks_to_ignore = ["bugs", "wm", "s3", "s4"]
notebooks = []
for path in BASE_DIR.iterdir():
if path.is_dir():
if any(ignored in path.name for ignored in notebooks_to_ignore):
continue
if ".github" in str(path):
continue
for nb in path.rglob("*_sol.ipynb"):
notebooks.append(nb.resolve())
#%%
# test function
@pytest.mark.parametrize("path", notebooks, ids=lambda p: str(p))
def test_notebook_runs(path: Path) -> None:
print(f"Testing notebook: {path.name}")
pm.execute_notebook(
input_path=str(path),
output_path=None,
log_output=True,
kernel_name="python3",
cwd=str(path.parent),
)

#%%
# local test
# for path in sorted(notebooks):
# test_notebook_runs(path=path)
30 changes: 30 additions & 0 deletions .github/workflows/test_notebooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test Notebooks

on:
push:
branches:
- master
schedule:
# Run on the first day of every month at 00:00 UTC
- cron: '0 0 1 * *'

jobs:
test-notebooks:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[ci]

- name: Run notebook tests
run: pytest .github/workflows/test_notebooks.py
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ ENV/
.ropeproject

.DS_Store

*.egg-info/
*.ipynb_checkpoints
*.lock
70 changes: 16 additions & 54 deletions notebook3_for_and_if/py_exploratory_comp_3_sol.ipynb

Large diffs are not rendered by default.

222 changes: 113 additions & 109 deletions notebook8_pandas/py_exploratory_comp_8_sol.ipynb

Large diffs are not rendered by default.

58 changes: 24 additions & 34 deletions notebook9_discrete_random_variables/py_exploratory_comp_9_sol.ipynb

Large diffs are not rendered by default.

363 changes: 236 additions & 127 deletions notebook_adv5/py_exp_comp_adv5_sol.ipynb

Large diffs are not rendered by default.

Loading