Unit Test PlasmaPy #73
This file contains 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: Unit Test PlasmaPy | |
on: | |
# push: | |
# branches: [main] | |
pull_request: | |
branches: [main] | |
schedule: | |
- cron: '0 0 * * *' # daily | |
workflow_dispatch: | |
pull_request_target: | |
types: [opened, synchronize, reopened] | |
jobs: | |
test: | |
runs-on: ubuntu-latest # TODO: make this `["ubuntu-latest", "windows-latest", "macos-latest"]`? | |
strategy: | |
matrix: | |
python-version: ["3.10", "3.11", "3.12"] # TODO: add 3.13 eventually | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install core PyHC packages # Install all dependencies listed in pyproject.toml | |
run: | | |
python -m pip install --upgrade pip | |
pip install .[tests] # include optional test dependencies | |
- name: Get PlasmaPy version | |
id: plasmapy_version | |
run: | | |
echo "PLASMAPY_VERSION=$(python -c 'import plasmapy; print(plasmapy.__version__)')" >> $GITHUB_ENV | |
# Mark tests as successful if 98%+ pass | |
- name: Clone and test PlasmaPy | |
shell: bash | |
env: | |
PLASMAPY_VERSION: ${{ env.PLASMAPY_VERSION }} | |
run: | | |
# Clone matching version of PlasmaPy repository | |
plasmapy_version="${PLASMAPY_VERSION}" | |
if [ -z "$plasmapy_version" ]; then | |
echo "PlasmaPy version not found." | |
exit 1 | |
fi | |
echo "Cloning PlasmaPy version $plasmapy_version" | |
plasmapy_version_tag="${plasmapy_version%%.dev*}" | |
git clone --branch "v$plasmapy_version_tag" "https://github.com/PlasmaPy/PlasmaPy.git" | |
cd PlasmaPy | |
# Run the tests (ignoring tests that require GH_TOKEN) | |
python -m pytest \ | |
--junitxml=test-results.xml \ | |
--continue-on-collection-errors \ | |
--ignore=tests/utils/data/test_downloader.py || true | |
# Analyze test results | |
python <<EOF | |
import sys | |
import xml.etree.ElementTree as ET | |
# Parse the XML file | |
tree = ET.parse('test-results.xml') | |
root = tree.getroot() | |
# Initialize counters | |
total = errors = failures = skipped = 0 | |
if root.tag == 'testsuites': | |
# Sum over all testsuite elements | |
for testsuite in root.findall('testsuite'): | |
total += int(testsuite.attrib.get('tests', 0)) | |
errors += int(testsuite.attrib.get('errors', 0)) | |
failures += int(testsuite.attrib.get('failures', 0)) | |
skipped += int(testsuite.attrib.get('skipped', 0)) | |
elif root.tag == 'testsuite': | |
# Single testsuite | |
total = int(root.attrib.get('tests', 0)) | |
errors = int(root.attrib.get('errors', 0)) | |
failures = int(root.attrib.get('failures', 0)) | |
skipped = int(root.attrib.get('skipped', 0)) | |
else: | |
print(f'Unexpected root tag: {root.tag}') | |
sys.exit(1) | |
# Count skipped tests as passed | |
passed = total - errors - failures | |
pass_rate = (passed / total) * 100 if total > 0 else 0 | |
print(f'Total tests: {total}') | |
print(f'Passed: {passed} (including skipped)') | |
print(f'Failures: {failures}') | |
print(f'Errors: {errors}') | |
print(f'Skipped: {skipped}') | |
print(f'Pass rate: {pass_rate:.2f}%') | |
if pass_rate >= 98: | |
print('Pass rate is above 98%, acceptable.') | |
sys.exit(0) | |
else: | |
print('Pass rate is below threshold of 98%.') | |
sys.exit(1) | |
EOF |