Skip to content

Tests

Tests #160

Workflow file for this run

# SPDX-FileCopyrightText: PyPSA Contributors
#
# SPDX-License-Identifier: MIT
name: Tests
on:
push:
branches:
- master
- release-branch-v*
pull_request:
branches: ["*"]
schedule:
- cron: "0 5 * * *"
# Cancel any in-progress runs when a new run is triggered
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
# Build the Python SDist and wheel, performs metadata and readme linting
name: Build and verify package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # Needed for setuptools_scm
- uses: hynek/build-and-inspect-python-package@v2
id: baipp
outputs:
python-versions: ${{ steps.baipp.outputs.supported_python_classifiers_json_array }}
test:
# Test package build in matrix of OS and Python versions
name: Test package
needs: [build]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJSON(needs.build.outputs.python-versions) }}
os:
- ubuntu-latest
- macos-latest
- windows-latest
api: [default, new_api]
exclude:
- os: macos-latest
api: new_api
- os: windows-latest
api: new_api
env:
MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # Needed for setuptools_scm
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install macos dependencies
if: matrix.os == 'macos-latest'
run: |
brew update
# pkg-config is deprecated but still installed in runner
# Can be removed once it is removed from the runner
brew unlink pkg-config@0.29.2 || true
brew install hdf5
- name: Download package
uses: actions/download-artifact@v7
with:
name: Packages
path: dist
- name: Install package and dependencies
if: matrix.python-version != '3.14'
run: |
python -m pip install uv
uv sync --all-extras --no-install-project
uv pip install "$(ls dist/*.whl)"
- name: Install package and dependencies (Python 3.14)
if: matrix.python-version == '3.14'
run: |
python -m pip install uv
uv sync --extra dev --no-install-project
uv pip install "$(ls dist/*.whl)"
- name: Run unit tests (old API)
if: matrix.api == 'default'
run: >
uv run pytest --mpl --mpl-generate-summary=html --mpl-results-path=mpl-results
--cov=pypsa --junitxml=junit.xml -o junit_family=legacy
&& uv run coverage xml
- name: Run unit tests (new API)
if: matrix.api == 'new_api'
run: >
uv run pytest
--new-components-api
--mpl --mpl-generate-summary=html --mpl-results-path=mpl-results
--cov=pypsa --junitxml=junit.xml -o junit_family=legacy
&& uv run coverage xml
- name: Upload artifacts
if: matrix.api == 'default' && matrix.os == 'macos-latest' && matrix.python-version == '3.13'
uses: actions/upload-artifact@v6
with:
name: results-plotting
path: |
mpl-results
retention-days: 14
if-no-files-found: ignore
- name: Upload code coverage report
if: ${{ !cancelled() }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: >
unit-tests,
os-${{ matrix.os }},
python${{ matrix.python-version }},
api-${{ matrix.api }}
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: >
unit-tests,
os-${{ matrix.os }},
python${{ matrix.python-version }},
api-${{ matrix.api }}
check-docs:
name: Check docs
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # Needed for setuptools_scm
- name: Set up Python 3.13
uses: actions/setup-python@v6
with:
python-version: 3.13
- name: Download package
uses: actions/download-artifact@v7
with:
name: Packages
path: dist
- name: Install package and dependencies
run: |
python -m pip install uv
uv sync --all-extras --no-install-project
uv pip install "$(ls dist/*.whl)"
- name: Run doc tests
run: >
uv run pytest
test/test_docs.py --test-docs
--cov=pypsa --junitxml=junit.xml -o junit_family=legacy
&& uv run coverage xml
- name: Upload code coverage report
if: ${{ !cancelled() }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: >
doc-tests,
os-ubuntu-latest,
python3.13,
api-old-api
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: >
doc-tests,
os-ubuntu-latest,
python3.13,
api-old-api
check-types:
name: Check types
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # Needed for setuptools_scm
- name: Set up Python 3.13
uses: actions/setup-python@v6
with:
python-version: 3.13
- name: Download package
uses: actions/download-artifact@v7
with:
name: Packages
path: dist
- name: Install package and dependencies
run: |
python -m pip install uv
uv sync --all-extras --no-install-project
uv pip install "$(ls dist/*.whl)"
- name: Run type checker (mypy)
run: |
uv run mypy .