Skip to content

Tests

Tests #968

Workflow file for this run

name: Tests
on:
push:
branches:
- main
pull_request:
paths:
- .github/workflows/tests.yml
- pyproject.toml
- s2fft/**
- tests/**
- .coveragerc
- CMakesLists.txt
schedule:
- cron: 0 0 * * 0
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
tests-non-cached:
# Test job run on Ubuntu runner only which installs full set of test dependencies
# and generates test data using external packages such as healpy, pyssht and so3
# which is then cached to allow use in a subsequent matrix test job
runs-on: ubuntu-latest
env:
# Required to avoid error when trying to build so3
CMAKE_POLICY_VERSION_MINIMUM: 3.5
steps:
- name: Checkout Source
uses: actions/checkout@v6.0.3
with:
fetch-depth: 0
fetch-tags: true
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.13"
cache: pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[tests]
- name: Run tests
# We run only tests which update cached data or explicitly require pyssht or healpy
run: |
pytest -v --cov-report=xml --cov=s2fft --cov-config=.coveragerc --update-cache -m "uses_cached_data or pyssht or healpy"
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v6
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload cached test data
uses: actions/upload-artifact@v7
with:
name: cached-test-data
path: tests/cached-test-data
retention-days: 30
tests-with-cached-data:
# Matrix test job using cached test data from previous job to allow running tests
# with a smaller set of dependencies (in particular not requiring pyssht, so3 or
# healpy to be installed to avoid issues when trying to build these packages)
runs-on: ${{ matrix.os }}
needs: tests-non-cached
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
os: [ubuntu-latest, macos-latest, windows-latest]
fail-fast: false
steps:
- name: Checkout Source
uses: actions/checkout@v6.0.3
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/download-artifact@v8
with:
name: cached-test-data
path: tests/cached-test-data
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install dependencies
# We install the subset of test dependencies required for running tests when
# cached test data is available
run: |
python -m pip install --upgrade pip
python -m pip install .[tests-cached]
- name: Run tests using cached data (skipping slow, on PRs only)
if: github.event_name == 'pull_request'
# Skip additional tests explicitly requiring pyssht or healpy as well as slow tests
run: |
pytest -v --cov-report=xml --cov=s2fft --cov-config=.coveragerc -m "not slow and not pyssht and not healpy" --use-cache
- name: Run tests using cached data (non-PRs)
if: github.event_name != 'pull_request'
# Skip additional tests explicitly requiring pyssht or healpy
run: |
pytest -v --cov-report=xml --cov=s2fft --cov-config=.coveragerc -m "not pyssht and not healpy" --use-cache
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v6
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}