Skip to content

Commit

Permalink
fix: Override error on filterwarnings to pass notebook tests (#1841)
Browse files Browse the repository at this point in the history
* Use 'scrapbook' as it is the new name of 'nteract-scrapbook', which is no longer
maintained or developed.
* Restrict 'papermill' and 'scrapbook' to compatible releases at the patch level
for API stability.
* Override error on filterwarnings for the 'notebooks' GHA workflow as it is testing
for the notebooks to run with the latest pyhf API, not if the Jupyter infrastructure
is warning free.
* Use the papermill.execute_notebook 'cwd' optional argument to change the execution
directory safely.
* Use a concurrency group to limit the notebook testing workflow to only one run
at a time.
   - c.f. https://docs.github.com/en/actions/using-jobs/using-concurrency
  • Loading branch information
matthewfeickert committed Apr 6, 2022
1 parent e8cb581 commit 8c581b5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
- cron: '1 0 * * *'
workflow_dispatch:

concurrency:
group: notebooks-${{ github.ref }}
cancel-in-progress: true

jobs:
test:

Expand All @@ -16,15 +20,23 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip --quiet install --upgrade .[complete]
python -m pip list
python -m pip install --upgrade .[test]
- name: List installed Python packages
run: python -m pip list

- name: Test example notebooks
run: |
pytest tests/test_notebooks.py
# Override the ini option for filterwarnings with an empty list to disable error
# on filterwarnings as testing for notebooks to run with the latest API, not if
# Jupyter infrastructure is warning free.
pytest --override-ini filterwarnings= tests/test_notebooks.py
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
'pytest-console-scripts',
'pytest-mpl',
'pydocstyle',
'papermill~=2.0',
'nteract-scrapbook~=0.2',
'papermill~=2.3.4',
'scrapbook~=0.5.0',
'jupyter',
'graphviz',
]
Expand Down
40 changes: 21 additions & 19 deletions tests/test_notebooks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import sys
import os
from pathlib import Path

import papermill as pm
import scrapbook as sb
import pytest
import scrapbook as sb


@pytest.fixture()
Expand All @@ -11,6 +12,7 @@ def common_kwargs(tmpdir):
return {
'output_path': str(outputnb),
'kernel_name': f'python{sys.version_info.major}',
'progress_bar': False,
}


Expand All @@ -19,17 +21,19 @@ def test_hello_world(common_kwargs):


def test_xml_importexport(common_kwargs):
# Change directories to make users not have to worry about paths to follow example
execution_dir = Path.cwd() / "docs" / "examples" / "notebooks"
pm.execute_notebook(
'docs/examples/notebooks/XML_ImportExport.ipynb', **common_kwargs
execution_dir / "XML_ImportExport.ipynb", cwd=execution_dir, **common_kwargs
)


def test_statisticalanalysis(common_kwargs):
# The Binder example uses specific relative paths
cwd = os.getcwd()
os.chdir(os.path.join(cwd, 'docs/examples/notebooks/binderexample'))
pm.execute_notebook('StatisticalAnalysis.ipynb', **common_kwargs)
os.chdir(cwd)
execution_dir = Path.cwd() / "docs" / "examples" / "notebooks" / "binderexample"
pm.execute_notebook(
execution_dir / "StatisticalAnalysis.ipynb", cwd=execution_dir, **common_kwargs
)


def test_shapefactor(common_kwargs):
Expand All @@ -39,35 +43,33 @@ def test_shapefactor(common_kwargs):
def test_multichannel_coupled_histos(common_kwargs):
pm.execute_notebook(
'docs/examples/notebooks/multichannel-coupled-histo.ipynb',
parameters={'validation_datadir': 'validation/data'},
parameters={"validation_datadir": str(Path.cwd() / "validation" / "data")},
**common_kwargs,
)


def test_multibinpois(common_kwargs):
pm.execute_notebook(
'docs/examples/notebooks/multiBinPois.ipynb',
parameters={'validation_datadir': 'validation/data'},
parameters={"validation_datadir": str(Path.cwd() / "validation" / "data")},
**common_kwargs,
)
nb = sb.read_notebook(common_kwargs['output_path'])
assert nb.scraps['number_2d_successpoints'].data > 200


def test_pullplot(common_kwargs):
# Change directories to make users not have to worry about paths to follow example
cwd = os.getcwd()
os.chdir(os.path.join(cwd, "docs/examples/notebooks"))
pm.execute_notebook("pullplot.ipynb", **common_kwargs)
os.chdir(cwd)
execution_dir = Path.cwd() / "docs" / "examples" / "notebooks"
pm.execute_notebook(
execution_dir / "pullplot.ipynb", cwd=execution_dir, **common_kwargs
)


def test_impactplot(common_kwargs):
# Change directories to make users not have to worry about paths to follow example
cwd = os.getcwd()
os.chdir(os.path.join(cwd, "docs/examples/notebooks"))
pm.execute_notebook("ImpactPlot.ipynb", **common_kwargs)
os.chdir(cwd)
execution_dir = Path.cwd() / "docs" / "examples" / "notebooks"
pm.execute_notebook(
execution_dir / "ImpactPlot.ipynb", cwd=execution_dir, **common_kwargs
)


def test_toys(common_kwargs):
Expand Down

0 comments on commit 8c581b5

Please sign in to comment.