Skip to content

[MNT] testing code in README for correctness #447

[MNT] testing code in README for correctness

[MNT] testing code in README for correctness #447

Workflow file for this run

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: pytest
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
code-quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: install pre-commit
run: python3 -m pip install pre-commit
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
run: |
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr '\n' ' ')
echo "CHANGED_FILES=${CHANGED_FILES}" >> $GITHUB_ENV
- name: Print changed files
run: |
echo "Changed files: $CHANGED_FILES"
- name: Run pre-commit on changed files
run: |
if [ -n "$CHANGED_FILES" ]; then
pre-commit run --color always --files $CHANGED_FILES --show-diff-on-failure
else
echo "No changed files to check."
fi
pytest-nosoftdeps:
needs: code-quality
name: nosoftdeps (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
env:
MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
fail-fast: false # to not fail all combinations if just one fails
steps:
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
shell: bash
run: uv pip install ".[dev]" --no-cache-dir
env:
UV_SYSTEM_PYTHON: 1
- name: Show dependencies
run: uv pip list
- name: Test with pytest
run: |
pytest ./tests
pytest:
needs: pytest-nosoftdeps
name: (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
env:
MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
fail-fast: false # to not fail all combinations if just one fails
steps:
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
shell: bash
run: uv pip install ".[dev,all_extras]" --no-cache-dir
env:
UV_SYSTEM_PYTHON: 1
- name: Show dependencies
run: uv pip list
- name: Test with pytest
run: |
pytest ./tests
codecov:
name: coverage (${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: code-quality
env:
MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.12"]
steps:
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
shell: bash
run: uv pip install ".[dev,all_extras]" --no-cache-dir
env:
UV_SYSTEM_PYTHON: 1
- name: Show dependencies
run: uv pip list
- name: Generate coverage report
run: |
pip install pytest pytest-cov
pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
# if false in order to skip for now
if: false
uses: codecov/codecov-action@v5
with:
files: ./coverage.xml
fail_ci_if_error: true
notebooks:
needs: code-quality
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.10', '3.11', '3.12', '3.13', '3.14' ]
fail-fast: false
steps:
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
shell: bash
run: uv pip install ".[dev,all_extras,notebook_test]" --no-cache-dir
env:
UV_SYSTEM_PYTHON: 1
- name: Show dependencies
run: uv pip list
# Discover all notebooks
- name: Collect notebooks
id: notebooks
shell: bash
run: |
NOTEBOOKS=$(find cookbook -name '*.ipynb' -print0 | xargs -0 echo)
echo "notebooks=$NOTEBOOKS" >> $GITHUB_OUTPUT
# Run all discovered notebooks with nbmake
- name: Test notebooks
shell: bash
run: |
uv run pytest --reruns 3 --nbmake --nbmake-timeout=3600 -vv ${{ steps.notebooks.outputs.notebooks }}