Skip to content

Commit

Permalink
Merge pull request #417 from bwheelz36/add_run_notebooks_test
Browse files Browse the repository at this point in the history
Add run notebooks test
  • Loading branch information
bwheelz36 committed May 9, 2023
2 parents 0baf8e1 + 4598cf4 commit af1adc6
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 146 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions


name: tests

on:
Expand All @@ -27,14 +26,21 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Install test dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install pytest-cov
pip install coverage
- name: Install notebook dependencies
run: |
pip install nbformat
pip install nbconvert
pip install jupyter
pip install matplotlib
- name: Install package
run: |
pip install -e .
- name: Test with pytest
run: |
pytest --cov-report xml --cov=bayes_opt/
Expand Down
4 changes: 2 additions & 2 deletions examples/basic-tour.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -501,7 +501,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down
58 changes: 26 additions & 32 deletions examples/constraints.ipynb

Large diffs are not rendered by default.

62 changes: 33 additions & 29 deletions examples/domain_reduction.ipynb

Large diffs are not rendered by default.

148 changes: 68 additions & 80 deletions examples/visualization.ipynb

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions tests/test_notebooks_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
collect all notebooks in examples, and check that they run without error
"""

import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
from pathlib import Path
from glob import glob
this_file_loc = Path(__file__).parent

def check_notebook_runs(notebook_loc):

try:
with open(notebook_loc, encoding='utf8') as f:
nb = nbformat.read(f, as_version=4)
ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
ep.preprocess(nb, {'metadata': {'path': Path(notebook_loc).parent}})
except Exception as e:
print(f'failed to run notebook {notebook_loc}: rethrowing exception:')
raise e

def test_all_notebooks_run():
# get all notebooks:
notebooks = glob(str(this_file_loc.parent / 'examples' / '*.ipynb'))
notebooks_not_to_run = ['put_notebooks_to_skip_here']
for notebook in notebooks:
if any([nb in notebook for nb in notebooks_not_to_run]):
continue
check_notebook_runs(notebook)

0 comments on commit af1adc6

Please sign in to comment.