Skip to content

Commit d4ed3a6

Browse files
committed
added test that all notebooks run
1 parent 3e55ac6 commit d4ed3a6

File tree

6 files changed

+177
-185
lines changed

6 files changed

+177
-185
lines changed

.github/workflows/run_tests.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# This workflow will install Python dependencies, run tests and lint with a single version of Python
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
33

4-
54
name: tests
65

76
on:
@@ -27,14 +26,21 @@ jobs:
2726
uses: actions/setup-python@v3
2827
with:
2928
python-version: ${{ matrix.python-version }}
30-
- name: Install dependencies
29+
- name: Install test dependencies
3130
run: |
3231
python -m pip install --upgrade pip
3332
pip install pytest
3433
pip install pytest-cov
3534
pip install coverage
35+
- name: Install notebook dependencies
36+
run: |
37+
pip install nbformat
38+
pip install nbconvert
39+
pip install jupyter
40+
pip install matplotlib
41+
- name: Install package
42+
run: |
3643
pip install -e .
37-
3844
- name: Test with pytest
3945
run: |
4046
pytest --cov-report xml --cov=bayes_opt/

examples/basic-tour.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@
487487
],
488488
"metadata": {
489489
"kernelspec": {
490-
"display_name": "Python 3",
490+
"display_name": "Python 3 (ipykernel)",
491491
"language": "python",
492492
"name": "python3"
493493
},
@@ -501,7 +501,7 @@
501501
"name": "python",
502502
"nbconvert_exporter": "python",
503503
"pygments_lexer": "ipython3",
504-
"version": "3.5.2"
504+
"version": "3.9.6"
505505
}
506506
},
507507
"nbformat": 4,

examples/constraints.ipynb

Lines changed: 36 additions & 71 deletions
Large diffs are not rendered by default.

examples/domain_reduction.ipynb

Lines changed: 33 additions & 29 deletions
Large diffs are not rendered by default.

examples/visualization.ipynb

Lines changed: 68 additions & 80 deletions
Large diffs are not rendered by default.

tests/test_notebooks_run.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
collect all notebooks in examples, and check that they run without error
3+
"""
4+
5+
import nbformat
6+
from nbconvert.preprocessors import ExecutePreprocessor
7+
from pathlib import Path
8+
from glob import glob
9+
this_file_loc = Path(__file__).parent
10+
11+
def check_notebook_runs(notebook_loc):
12+
13+
try:
14+
with open(notebook_loc, encoding='utf8') as f:
15+
nb = nbformat.read(f, as_version=4)
16+
ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
17+
ep.preprocess(nb, {'metadata': {'path': Path(notebook_loc).parent}})
18+
except Exception as e:
19+
print(f'failed to run notebook {notebook_loc}: rethrowing exception:')
20+
raise e
21+
22+
def test_all_notebooks_run():
23+
# get all notebooks:
24+
notebooks = glob(str(this_file_loc.parent / 'examples' / '*.ipynb'))
25+
notebooks_not_to_run = ['put_notebooks_to_skip_here']
26+
for notebook in notebooks:
27+
if any([nb in notebook for nb in notebooks_not_to_run]):
28+
continue
29+
check_notebook_runs(notebook)

0 commit comments

Comments
 (0)