Skip to content

Commit bd8a031

Browse files
authored
ENH: Enable the running of notebooks in the mapie/tests/notebooks in CI. (#786)
* ENH: add the theoretical risk control validation notebook in the CI. * commande "make notebook-tests" * ajoute de commande * Add command in CI pipeline * make pytest to skip notebooks * install nbclient and jupyter in CI * handle exit(0) * ignore notebooks when checking coverage
1 parent 8ef758f commit bd8a031

File tree

9 files changed

+888
-545
lines changed

9 files changed

+888
-545
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,7 @@ jobs:
7373
run: make type-check
7474
- name: Test and coverage with pytest
7575
run: make coverage
76+
- name: Test notebooks
77+
run: make notebook-tests
7678
- name: Code coverage
7779
run: codecov

CONTRIBUTING.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ The coverage should absolutely be 100%.
8181
8282
$ make coverage
8383
84+
If your modification affects notebook-based experiments in ``mapie/tests/notebooks/``,
85+
you should also ensure that all notebooks run successfully.
86+
87+
.. code-block:: sh
88+
89+
$ make notebook-tests
90+
8491
Documenting your change
8592
-----------------------
8693

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ coverage:
2222
--no-cov-on-fail \
2323
--doctest-modules
2424

25-
2625
### Checks that are run in ReadTheDocs CI ###
2726
doc:
2827
$(MAKE) html -C doc
@@ -39,7 +38,7 @@ all-checks:
3938
$(MAKE) coverage
4039

4140
tests:
42-
pytest -vs --doctest-modules mapie
41+
pytest -vs --doctest-modules mapie --ignore=mapie/tests/notebooks
4342

4443
clean-doc:
4544
$(MAKE) clean -C doc
@@ -55,3 +54,8 @@ clean:
5554
rm -rf **__pycache__
5655
$(MAKE) clean-build
5756
$(MAKE) clean-doc
57+
58+
# Run all notebooks located in mapie/tests/notebooks/
59+
notebook-tests:
60+
@echo "Executing all notebooks in mapie/tests/notebooks/..."
61+
python mapie/tests/notebooks/_run_notebooks.py

environment.ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ dependencies:
88
- mypy<1.15
99
- pandas
1010
- pytest-cov
11+
- jupyter
12+
- nbclient

mapie/tests/notebooks/__init__.py

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# pragma: no cover
2+
import sys
3+
from pathlib import Path
4+
5+
from nbclient import NotebookClient
6+
from nbformat import read
7+
8+
NOTEBOOKS_DIR = Path(__file__).parent
9+
notebooks = NOTEBOOKS_DIR.rglob("*.ipynb")
10+
11+
if __name__ == "__main__": # pragma: no cover
12+
for nb_path in notebooks:
13+
print(f"Running {nb_path} ...")
14+
try:
15+
with nb_path.open() as f:
16+
nb = read(f, as_version=4)
17+
client = NotebookClient(nb, timeout=3600)
18+
client.execute()
19+
except Exception as e:
20+
print(f"Notebook {nb_path} failed:\n{e}")
21+
sys.exit(1)
22+
23+
print("\nAll notebooks executed successfully. 100% OK.\n")
24+
sys.exit(0)

0 commit comments

Comments
 (0)