Skip to content

Fix broken tests

Fix broken tests #64

Workflow file for this run

name: Tests
on:
push:
paths:
- '**/*.py'
pull_request:
paths:
- '**/*.py'
workflow_dispatch:
jobs:
tests:
name: Run Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.test.txt
pip install pytest pytest-cov
- name: Run tests with coverage
run: |
python -m pytest --cov --cov-report json
- name: Fail if coverage under 95%
run: |
# Load coverage percentage from coverage.json
coverage_percent=$(python -c 'import json; print(json.load(open("coverage.json"))["totals"]["percent_covered"])')
echo "Coverage percentage: ${coverage_percent}%"
# Check if coverage is below the threshold
if (( $(echo "${coverage_percent} < 95" | bc -l) )); then
echo "Test coverage under 95%, was ${coverage_percent}%"
exit 1
else
echo "Coverage meets the threshold."
fi
- name: Upload .coverage for main branch
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: coverage-data
path: .coverage
update-coverage-badge:
name: Update Coverage Badge
runs-on: ubuntu-latest
needs: tests
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Download .coverage
uses: actions/download-artifact@v4
with:
name: coverage-data
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install coverage-badge
run: |
pip install coverage-badge
- name: Generate coverage badge
run: |
mkdir -p badges
coverage-badge -o badges/coverage.svg
- name: Upload coverage badge for gh-pages
uses: actions/upload-artifact@v4
with:
name: coverage-badge
path: badges/coverage.svg
commit-coverage-badge:
name: Commit Coverage Badge
runs-on: ubuntu-latest
needs: update-coverage-badge
if: github.ref == 'refs/heads/main'
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: gh-pages
- name: Download coverage badge
uses: actions/download-artifact@v4
with:
name: coverage-badge
path: badges
- name: Deploy Badge to gh-pages
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update coverage badge [skip ci]"
branch: gh-pages
file_pattern: badges/coverage.svg