From 40989a3c1c2f6de5803fb940f361d229e3c21efa Mon Sep 17 00:00:00 2001 From: Harrison Nicholls Date: Fri, 6 Sep 2024 18:25:59 +0200 Subject: [PATCH] Tests and linting --- .github/workflows/tests.yaml | 72 ++++++++++++++++++++++++++++++++++++ README.md | 6 ++- tests/test_init.py | 7 ++++ 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/tests.yaml create mode 100644 tests/test_init.py diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..f93d644 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,72 @@ +name: Tests for PROTEUS + +on: + push: + branches: + - main + pull_request: + branches: + - main + types: + - opened + - reopened + - synchronize + - ready_for_review + workflow_dispatch: + +jobs: + test: + if: github.event.pull_request.draft == false + name: Run Coverage and Tests + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.10', '3.11', '3.12'] + + steps: + - uses: actions/checkout@v3 + with: + submodules: 'false' + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - uses: actions/cache@v3 + id: cache-virtualenv + with: + path: ${{ env.pythonLocation }} + key: ${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }} + + - name: Install dependencies + if: steps.cache-virtualenv.outputs.cache-hit != 'true' + run: | + python -m pip install -e .[develop] + + - name: Test with pytest + run: | + coverage run -m pytest + + - name: Report coverage + run: | + coverage json + export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])") + echo "total=$TOTAL" >> $GITHUB_ENV + echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY + echo $'\n```' >> $GITHUB_STEP_SUMMARY + coverage report >> $GITHUB_STEP_SUMMARY + echo $'\n```' >> $GITHUB_STEP_SUMMARY + + # - name: Make coverage badge + # if: ${{ github.ref == 'refs/heads/main' && matrix.python-version == '3.10' }} + # uses: schneegans/dynamic-badges-action@v1.7.0 + # with: + # auth: ${{ secrets.GIST_TOKEN }} + # gistID: b4ee7dab92e20644bcb3a5ad09f71165 + # filename: covbadge.svg + # label: Coverage + # message: ${{ env.total }}% + # minColorRange: 50 + # maxColorRange: 90 + # valColorRange: ${{ env.total }} diff --git a/README.md b/README.md index 7802150..a0a4462 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ +[![Tests for CALLIOPE](https://github.com/FormingWorlds/CALLIOPE/actions/workflows/tests.yaml/badge.svg)](https://github.com/FormingWorlds/CALLIOPE/actions/workflows/tests.yaml) +[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) + # CALLIOPE -Volatile delivery and planetary accretion model designed for integration into PROTEUS. +Numerical model for the equilibrium outgassing of volatiles from a magma ocean. Named after the [Greek muse of eloquence and epic poetry](https://en.wikipedia.org/wiki/Calliope). Prounounced: *kal-IGH-uh-pee*. @@ -7,4 +10,3 @@ Prounounced: *kal-IGH-uh-pee*. ## Installation Simply run `pip install -e .` in this folder and `calliope` will be added to your Python environment. - diff --git a/tests/test_init.py b/tests/test_init.py new file mode 100644 index 0000000..48ba89a --- /dev/null +++ b/tests/test_init.py @@ -0,0 +1,7 @@ +from __future__ import annotations + +from calliope import __version__ + + +def test_version(): + assert __version__