Skip to content

Commit dd2dc72

Browse files
martinvonkmbakker7
andauthored
Create test that runs the notebooks once every month (#16)
* Update all notebooks --------- Co-authored-by: Mark Bakker <markbak@gmail.com>
1 parent 9b05922 commit dd2dc72

46 files changed

Lines changed: 14795 additions & 8247 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

-26 KB
Binary file not shown.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#%%
2+
# depenencies
3+
from pathlib import Path
4+
import papermill as pm
5+
import pytest
6+
7+
#%%
8+
# paths
9+
CWD = Path(__file__).parent.resolve()
10+
BASE_DIR = CWD.parent.parent
11+
12+
#%%
13+
# Collect all notebooks you want to test
14+
notebooks = []
15+
for path in BASE_DIR.iterdir():
16+
if path.is_dir():
17+
for nb in path.rglob("*_sol.ipynb"):
18+
notebooks.append(nb.resolve())
19+
#%%
20+
# test function
21+
@pytest.mark.parametrize("path", notebooks, ids=lambda p: str(p))
22+
def test_notebook_runs(path: Path) -> None:
23+
print(f"Testing notebook: {path.name}")
24+
if "bugs" in str(path):
25+
with pytest.raises(Exception):
26+
pm.execute_notebook(
27+
input_path=str(path),
28+
output_path=None,
29+
log_output=True,
30+
kernel_name="python3",
31+
cwd=str(path.parent),
32+
)
33+
else:
34+
pm.execute_notebook(
35+
input_path=str(path),
36+
output_path=None,
37+
log_output=True,
38+
kernel_name="python3",
39+
cwd=str(path.parent),
40+
)
41+
42+
#%%
43+
# local test
44+
# for path in sorted(notebooks):
45+
# if "bugs" in str(path):
46+
# continue
47+
# test_notebook_runs(path=path)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Test Notebooks
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
schedule:
8+
# Run on the first day of every month at 00:00 UTC
9+
- cron: '0 0 1 * *'
10+
11+
jobs:
12+
test-notebooks:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v6
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v6
21+
with:
22+
python-version: '3.x'
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -e .[ci]
28+
29+
- name: Run notebook tests
30+
run: pytest .github/workflows/test_notebooks.py

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,8 @@ ENV/
9090
.ropeproject
9191

9292
.DS_Store
93+
94+
*.egg-info/
95+
*.ipynb_checkpoints
96+
*.lock
97+
*.DS_Store

notebook10_continuous_random_variables/py_exploratory_comp_10.ipynb

Lines changed: 718 additions & 0 deletions
Large diffs are not rendered by default.

notebook10_continuous_random_variables/py_exploratory_comp_10_sol.ipynb

Lines changed: 84 additions & 104 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)