-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial notebook testing framework (#480)
* Initial notebook testing framework * Update single notebook workflow * Add new test notebook * Fix typos in pip install * Checking for changes is done by GA * Remove tmate debugging session * Only run on non-draft PRs * Rename workflow files * Enable trigger for going off draft mode on PRs * Update regular tests to run on alibi directory only * Rename job * Remove test notebook * Disable regular cronjob for now * Add module docstring for testing example script
- Loading branch information
Showing
5 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# This workflows executes all example notebooks to ensure they are up-to-date. | ||
|
||
name: test_all_notebooks | ||
|
||
on: | ||
# Trigger the workflow on manual dispatch and once a week | ||
workflow_dispatch | ||
# schedule: | ||
# - cron: '0 0 * * 0' | ||
|
||
jobs: | ||
test_notebooks: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [ '3.6', '3.7', '3.8', '3.9' ] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
pip install --upgrade pip setuptools | ||
pip install --upgrade --upgrade-strategy eager -r requirements/dev.txt | ||
pip install --upgrade --upgrade-strategy eager -e . | ||
pip install --upgrade --upgrade-strategy eager -e .[examples] | ||
pip install --upgrade --upgrade-strategy eager -e .[ray] | ||
pip install --upgrade --upgrade-strategy eager -e .[shap] | ||
python -m spacy download en_core_web_md | ||
pip freeze | ||
- name: Run notebooks | ||
run: | | ||
pytest --nbmake examples/**/*.ipynb | ||
# pytest -rA --durations=0 -vv testing/test_notebooks.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# This workflows executes new or modified example notebooks. | ||
|
||
name: test_changed_notebooks | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
paths: | ||
- 'examples/**/*.ipynb' | ||
pull_request: | ||
branches: | ||
- master | ||
paths: | ||
- 'examples/**/*.ipynb' | ||
types: [opened, synchronize, reopened, ready_for_review] | ||
|
||
jobs: | ||
test_changed_notebooks: | ||
if: github.event.pull_request.draft == false | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [ '3.6', '3.7', '3.8', '3.9' ] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Check for new or changed .ipynb files | ||
id: changed-ipynb | ||
uses: tj-actions/[email protected] | ||
with: | ||
files: | | ||
examples/*.ipynb | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
pip install --upgrade pip setuptools | ||
pip install --upgrade --upgrade-strategy eager -r requirements/dev.txt | ||
pip install --upgrade --upgrade-strategy eager -e . | ||
pip install --upgrade --upgrade-strategy eager -e .[examples] | ||
pip install --upgrade --upgrade-strategy eager -e .[ray] | ||
pip install --upgrade --upgrade-strategy eager -e .[shap] | ||
python -m spacy download en_core_web_md | ||
pip freeze | ||
- name: Run notebooks | ||
run: | | ||
pytest --nbmake `echo ${{ steps.changed-ipynb.outputs.all_modified_files }}` | ||
# for file in "${{ steps.changed-ipynb.outputs.all_modified_files }}"; do | ||
# python testing/test_notebooks.py $file | ||
# done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
This script is an example of using `jupytext` to execute notebooks for testing instead of relying on `nbmake` | ||
plugin. This approach may be more flexible if our requirements change in the future. | ||
""" | ||
|
||
import argparse | ||
import glob | ||
import pytest | ||
from jupytext.cli import jupytext | ||
|
||
# list of all example notebooks | ||
notebooks = glob.glob('examples/*.ipynb') | ||
|
||
|
||
@pytest.mark.timeout(300) | ||
@pytest.mark.parametrize("notebook", notebooks) | ||
def test_notebook_execution(notebook): | ||
jupytext(args=[notebook, "--execute"]) | ||
|
||
|
||
if __name__ == '__main__': | ||
# When run as a script, execute the notebook passed on the command line | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('notebook', type=str) | ||
args = parser.parse_args() | ||
|
||
test_notebook_execution(args.notebook) |