-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from FormingWorlds/testing
Testing
- Loading branch information
Showing
7 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: Tests for MORS | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ['3.10', '3.11', '3.12'] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup system | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install libnetcdff-dev netcdf-bin | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- uses: actions/cache@v3 | ||
id: cache-virtualenv | ||
with: | ||
path: ${{ env.pythonLocation }} | ||
key: ${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }} | ||
|
||
- name: Build MORS | ||
if: steps.cache-virtualenv.outputs.cache-hit != 'true' | ||
run: | | ||
python -m pip install -e .[develop] | ||
- uses: actions/cache@v3 | ||
id: cache-fwl-data | ||
with: | ||
path: /home/runner/work/fwl_data | ||
key: fwl-data-1 | ||
|
||
- name: Test with pytest | ||
run: | | ||
export FWL_DATA="/home/runner/work/fwl_data" | ||
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/master' && matrix.python-version == '3.10' }} | ||
uses: schneegans/[email protected] | ||
with: | ||
auth: ${{ secrets.GIST_TOKEN }} | ||
gistID: a25c37a328839edd00bb32d8527aec30 | ||
filename: covbadge.svg | ||
label: Coverage | ||
message: ${{ env.total }}% | ||
minColorRange: 50 | ||
maxColorRange: 90 | ||
valColorRange: ${{ env.total }} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import mors | ||
import pytest | ||
from numpy.testing import assert_allclose | ||
|
||
TEST_DATA = ( | ||
((0.047, 8.5e7, 0.75),(0.74306071e-3, 0.14300000, 1.79809587 )), | ||
((1.113, 3.2e9, 1.05),(1.65441005 , 1.18216231, 2.04256380e3)), | ||
) | ||
|
||
@pytest.mark.parametrize("inp,expected", TEST_DATA) | ||
def test_baraffe(inp, expected): | ||
|
||
mors.DownloadEvolutionTracks('Baraffe') | ||
baraffe = mors.BaraffeTrack(inp[0]) | ||
ret = ( | ||
baraffe.BaraffeLuminosity(inp[1]), | ||
baraffe.BaraffeStellarRadius(inp[1]), | ||
baraffe.BaraffeSolarConstant(inp[1], inp[2]), | ||
) | ||
|
||
assert_allclose(ret, expected, rtol=1e-5, atol=0) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import mors | ||
import pytest | ||
from numpy.testing import assert_allclose | ||
|
||
TEST_DATA = ( | ||
((0.128, 45.2, 8.5e1),(0.21263373, 1.68612613e+31, 1.74497354e+28)), | ||
((1.113, 17.7, 3.2e3),(1.16581856, 6.81769993e+33, 7.95296357e+28)), | ||
) | ||
|
||
@pytest.mark.parametrize("inp,expected", TEST_DATA) | ||
def test_spada(inp, expected): | ||
|
||
mors.DownloadEvolutionTracks('Spada') | ||
star = mors.Star(Mstar=inp[0], Omega=inp[1]) | ||
ret = ( | ||
star.Value(inp[2], 'Rstar'), | ||
star.Value(inp[2], 'Lbol'), | ||
star.Value(inp[2], 'Leuv'), | ||
) | ||
|
||
assert_allclose(ret, expected, rtol=1e-5, atol=0) |
File renamed without changes.