Skip to content

Commit

Permalink
use GitHub actions for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbant committed Aug 21, 2024
1 parent 6371dc9 commit 55edb9c
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 155 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
os: [ macos-12, macos-13-xlarge, macos-14, ubuntu-latest, windows-latest ]

steps:
- uses: fortran-lang/setup-fortran@main
if: matrix.os == 'windows-latest'
id: setup-fortran
with:
compiler: gcc
version: 13
# - uses: fortran-lang/setup-fortran@main
# if: matrix.os == 'windows-latest'
# id: setup-fortran
# with:
# compiler: gcc
# version: 13

- run: ln -s $(which gfortran-14) /usr/local/bin/gfortran
if: matrix.os != 'windows-latest' && matrix.os != 'ubuntu-latest'
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.x"
cache: pip
cache-dependency-path: "setup.py"

Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/test_fortran.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build and Test Fortran

on:
push:
branches-ignore:
- 'test**'
pull_request:

jobs:
fortran-test:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != 'cmbant/camb')

steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install python requirements
run: python -m pip install numpy

- name: Run Build and Test Script
run: bash fortran/tests/run_tests.sh

- name: Upload Test Files on Failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-output-${{ github.sha }}
path: fortran/testfiles/
if-no-files-found: warn
61 changes: 61 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Python tests

on: [push, pull_request]

jobs:
python_tests:
runs-on: ubuntu-latest
if: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != 'cmbant/camb')
strategy:
fail-fast: false
matrix:
include:
- name: "Latest Python 3.x"
os: ubuntu-latest
python-version: 3.x
- name: "OS X Python 3.8"
os: macos-latest
python-version: 3.8
- name: "Windows Python 3.12"
os: windows-latest
python-version: 3.12

steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- run: ln -s $(which gfortran-14) /usr/local/bin/gfortran
if: matrix.os == 'macos-latest'

- name: flake8 Lint
if: matrix.os == 'ubuntu-latest'
uses: py-actions/flake8@v2
with:
args: --select=E713,E704,E703,E714,E10,E11,E20,E22,E23,E25,E27,E301,E302,E304,E9,F405,F406,F5,F6,F7,F8,W1,W2,W3,W6 --show-source --statistics
path: camb
max-line-length: "120"

- name: Install dependencies
run: |
python --version
gfortran --version
pip install -e .
- name: Run tests
run: |
python -c "import camb; print(camb.__version__)"
python -m unittest camb.tests.camb_test
- name: HM code tests
if: matrix.os == 'ubuntu-latest'
run: |
git clone https://github.com/alexander-mead/HMcode_test_outputs.git
python -m unittest camb.tests.hmcode_test
94 changes: 0 additions & 94 deletions .travis.yml

This file was deleted.

7 changes: 3 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ CAMB
:target: https://anaconda.org/conda-forge/camb
.. image:: https://readthedocs.org/projects/camb/badge/?version=latest
:target: https://camb.readthedocs.io/en/latest
.. image:: https://img.shields.io/travis/com/cmbant/camb
:target: https://app.travis-ci.com/cmbant/camb/builds
.. image:: https://github.com/cmbant/camb/actions/workflows/tests.yml/badge.svg?branch=master
:target: https://github.com/cmbant/CAMB/actions
.. image:: https://mybinder.org/badge_logo.svg
:target: https://mybinder.org/v2/gh/cmbant/CAMB/HEAD?filepath=docs%2FCAMBdemo.ipynb

Expand Down Expand Up @@ -57,8 +57,7 @@ Branches

The master branch contains latest changes to the main release version.

The devel branch contains latest less-stable things in development.
The master and devel branches have an integrated test suite, which runs automatically on `Travis <https://travis-ci.org>`_ for new commits and pull requests.
There isa a test suite, which runs automatically on GitHub actions for new commits and pull requests.
Reference results and test outputs are stored in the `test outputs repository <https://github.com/cmbant/CAMB_test_outputs/>`_. Tests can also be run locally.

To reproduce legacy results, see these branches:
Expand Down
2 changes: 1 addition & 1 deletion camb/tests/camb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from camb import model, correlations, bbn, dark_energy, initialpower
from camb.baseconfig import CAMBParamRangeError, CAMBValueError

fast = 'ci fast' in os.getenv("TRAVIS_COMMIT_MESSAGE", "") or os.getenv("GITHUB_ACTIONS")
fast = 'ci fast' in os.getenv("GITHUB_ACTIONS")


class CambTest(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions fortran/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ <H3>Compilation options and code modifications</H3>
See the <a href="https://camb.info/doc/classes/_index.html">class hierarchy</a> for how the different components of the calculation are structured.
Some details about what different source code files do are given <A HREF="#FILES">below</A>, see also the <A HREF="https://cosmologist.info/notes/CAMB.pdf">CAMB notes</A>.
<P>
A test suite is included, and will run automatically on <A HREF="https://travis-ci.com/">Travis</A> when committing or making pull requests on the <A HREF="https://github.com/cmbant/CAMB">GitHub repository</A>.
Python unit tests are in the camb.tests, and scripts for comparing outputs for a variety of models (as run on Travis) are in the tests directory.
A test suite is included, and will run automatically on GitHub when committing or making pull requests on the <A HREF="https://github.com/cmbant/CAMB">GitHub repository</A>.
Python unit tests are in the camb.tests, and scripts for comparing outputs for a variety of models are in the fortran/tests directory.

<A NAME="FILES">
<H3>The source files</H3>
Expand Down
26 changes: 3 additions & 23 deletions fortran/tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
set -e

gfortran --version
python --version
pip install -e .
python -c "import camb; print(camb.__version__)"
python -m unittest camb.tests.camb_test
rm -Rf HMcode_test_outputs
git clone https://github.com/alexander-mead/HMcode_test_outputs.git
python -m unittest camb.tests.hmcode_test
rm -Rf HMcode_test_outputs
pip uninstall -y camb
rm -Rf dist/*
rm -Rf build/*
rm -f camb/*.so

case "$TRAVIS_BRANCH" in
devel*)
BRANCH="master"
;;
*)
BRANCH="master"
;;
esac
gfortran --version

pushd fortran

Expand All @@ -32,8 +12,8 @@ mkdir -p testfiles
python tests/CAMB_test_files.py testfiles --make_ini

pushd testfiles
echo "cloning test output branch:" $BRANCH
git clone -b $BRANCH --depth=1 https://github.com/cmbant/CAMB_test_outputs.git
echo "cloning test output"
git clone --depth=1 https://github.com/cmbant/CAMB_test_outputs.git
popd

python tests/CAMB_test_files.py testfiles --diff_to CAMB_test_outputs/test_outputs --verbose
Expand Down
24 changes: 0 additions & 24 deletions fortran/tests/upload_tests.sh

This file was deleted.

0 comments on commit 55edb9c

Please sign in to comment.