Notebook Testing #101
This file contains hidden or 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
| name: Notebook Testing | |
| env: | |
| PYTHON_VERSION: "3.13" | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - 'docs/**' | |
| - 'binder/**' | |
| - 'figures/**' | |
| pull_request: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - 'docs/**' | |
| - 'binder/**' | |
| - 'figures/**' | |
| schedule: | |
| # run testing on the first of each month 5am ET / 9am UTC | |
| - cron: '0 9 1 * *' | |
| # Enable manual running of workflow, so we can force execution | |
| workflow_dispatch: | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Set up Python ${{ env.PYTHON_VERSION }} | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Install and run black for notebooks | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install black[jupyter] | |
| black --check --diff --verbose . | |
| test: | |
| needs: lint | |
| strategy: | |
| matrix: | |
| # using macos-15-intel, last available intel architecture. macos-latest is arm64 architecture. | |
| os: [ubuntu-latest, windows-latest, macos-latest, macos-15-intel] | |
| inputs: ["00_ or 01_ or 02_ or 03_ or 04_ or 05_", "06_ or 07_ or 08_ or 09_ or 10_"] | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: actions/cache@v4 | |
| id: cache | |
| with: | |
| path: | | |
| data | |
| key: notebook-data-${{ hashFiles('data/manifest.json') }} | |
| restore-keys: | | |
| notebook-data-${{ hashFiles('data/manifest.json') }} | |
| - name: Set up Python ${{ env.PYTHON_VERSION }} | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Install enchant on non windows systems | |
| shell: bash | |
| run: | | |
| if [ "$RUNNER_OS" == "Linux" ]; then | |
| sudo apt-get update | |
| sudo apt-get install enchant-2 | |
| elif [ "$RUNNER_OS" == "macOS" ]; then | |
| brew update | |
| brew install enchant | |
| fi | |
| # on windows, the pyenchant package includes enchant | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install -r tests/requirements_testing.txt | |
| jupyter nbextension enable --py --sys-prefix widgetsnbextension | |
| - name: Download data | |
| if: steps.cache.outputs.cache-hit != 'true' | |
| run: python downloaddata.py data/ data/manifest.json | |
| - name: run the test | |
| shell: bash | |
| env: | |
| SIMPLE_ITK_MEMORY_CONSTRAINED_ENVIRONMENT: 1 | |
| run: | # pyenchant has a problem locating libenchant on macOS-ARM64. setting this environment variable resolves the issue | |
| if [ "$RUNNER_OS" == "macOS" ] && [ "${{ matrix.os }}" != "macos-15-intel" ]; then | |
| export PYENCHANT_LIBRARY_PATH=/opt/homebrew/lib/libenchant-2.dylib | |
| fi | |
| pytest -v --tb=short -k "${{matrix.inputs}}" tests/test_notebooks.py::Test_notebooks::test_python_notebook |