Skip to content

Commit

Permalink
Merge pull request #22 from ACCESS-NRI/3-Package-model-config-tests
Browse files Browse the repository at this point in the history
Package model-config-tests
  • Loading branch information
jo-basevi authored May 24, 2024
2 parents b086103 + dff16de commit 809122d
Show file tree
Hide file tree
Showing 23 changed files with 642 additions and 358 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CD

on:
push:
tags:
- '*'

jobs:
pypi-build:
name: Build package for PyPI
if: github.repository == 'access-nri/model-config-tests'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install build dependencies
run: python3 -m pip install --upgrade build

- name: Build distributions
run: python3 -m build

- name: Upload distribution artifact
uses: actions/upload-artifact@v4
with:
name: release
path: dist

pypi-publish:
# Split build and publish to restrict trusted publishing to just this workflow
needs: ['pypi-build']
name: Publish to PyPI.org
runs-on: ubuntu-latest
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: release
path: dist

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf # v1.8.11
92 changes: 92 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: CI

on:
pull_request:
branches:
- 'main'

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd #v3.0.1

pypi-build:
name: Build package for PyPI
if: github.repository == 'access-nri/model-config-tests'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: 'pip'

- name: Install build dependencies
run: python3 -m pip install --upgrade build

- name: Build distributions
run: python3 -m build

- name: Upload distribution artifact
uses: actions/upload-artifact@v4
with:
name: release
path: dist

install_from_dist:
needs: [ 'pypi-build' ]
name: Test install from distribution
runs-on: ubuntu-latest
steps:
- name: Download distribution
uses: actions/download-artifact@v4
with:
name: release
path: dist

- name: Setup Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install model_config_tests
run: python3 -m pip install ./dist/model_config_tests-*.tar.gz

- name: Run model-config-tests command
run: model-config-tests --collect-only

tests:
name: Tests
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [ "3.9", "3.10", "3.11" ]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip

- name: Install model_config_tests with test dependencies
run: python3 -m pip install -e '.[test]'

- name: Run tests
run: python3 -m pytest -s --cov=./src --cov-report=xml tests

- name: Upload code coverage
uses: codecov/codecov-action@125fc84a9a348dbcf27191600683ec096ec9021c #v4.4.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.pyc
/__pycache__
/build
/dist
*.egg-info
.coverage
.ipynb_checkpoints
.vscode
.idea
/tests/tmp/
coverage.xml
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff
args: [ --fix ]

- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
language_version: python3
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ The checksum pytests are used for reproducibility CI checks in the [ACCESS-NRI/r
Code from these tests is adapted from COSIMAS's ACCESS-OM2's [
bit reproducibility tests](https://github.com/COSIMA/access-om2/blob/master/test/test_bit_reproducibility.py).

### How to run tests manually
### How to run tests manually (from a local install of model-config-tests)

1. First clone the pytest code into a separate directory.
```sh
git clone https://github.com/ACCESS-NRI/model-config-tests/ test-code
git clone https://github.com/ACCESS-NRI/model-config-tests/ model-config-tests
```

2. To create a local install of `model-config-tests`
```sh
cd model-config-tests
pip install --user -e .
model-config-tests --help # model-config-tests runs the pytest command for tests in the package
```

2. Checkout an experiment (in this case it is using an ACCESS-OM2 config)
Expand All @@ -25,17 +32,17 @@ git checkout <branch/tag>
3. Setup payu
```sh
module use /g/data/vk83/modules
module load payu/1.1
module load payu/1.1.3
```

4. Run the pytests
```sh
pytest <path/to/test-code>
model-config-tests
```

### Pytest Options

The output directory for pytests defaults to `/scratch/$PROJECT/$USER/test-model-repro` and contains the following sub-directories:
The output directory for pytests defaults to `$TMPDIR/test-model-repro` and contains the following subdirectories:
- `control` - contains copies of the model configuration used for each experiment run in the tests.
- `lab` - contains `payu` model output directories containing `work` and `archive` sub-directories.

Expand All @@ -44,7 +51,7 @@ This output directory also contains files generated by pytests, including the `C
To specify a different folder for pytest outputs, use `--output-path` command flag, for example:

```sh
pytest <path/to/test-code> --output-path /some/other/path/for/output
model-config-tests --output-path /some/other/path/for/output
```

By default, the control directory, e.g. the model configuration to test, is the current working directory. This can be set similarly to above by using the
Expand All @@ -57,13 +64,13 @@ file which is stored in the control directory.
To run only CI reproducibility checksum tests, use `-m checksum`, e.g.

```sh
pytest <path/to/test-code> -m checksum
model-config-tests -m checksum
```

To run quick configuration tests, use the `config` marker. To additionally run
ACCESS-OM2 specific quick configuration tests, use `access_om2` marker,
e.g.:

```sh
pytest <path/to/test-code> -m "config or access_om2"
model-config-tests -m "config or access_om2"
```
5 changes: 0 additions & 5 deletions models/__init__.py

This file was deleted.

33 changes: 0 additions & 33 deletions models/model.py

This file was deleted.

98 changes: 98 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[project]
name = "model_config_tests"
version = "0.0.1"
authors = [
{ name = "ACCESS-NRI" },
]
description = "Test for ACCESS model (payu) configurations"
readme = "README.md"
requires-python = ">=3.9"
license = { text = "Apache-2.0" }
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: POSIX :: Linux",
]
dependencies = [
"f90nml >=0.16",
"requests",
"PyYAML",
"requests",
"pytest >=8.0.1",
"ruamel.yaml >=0.18.5",
"jsonschema >=4.21.1"
]

[project.optional-dependencies]
test = [
"pytest-cov"
]

[project.scripts]
model-config-tests = "model_config_tests.__main__:main"

[project.urls]
Homepage = "https://github.com/ACCESS-NRI/model-config-tests/"
Issues = "https://github.com/ACCESS-NRI/model-config-tests/issues"

[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools >= 61.0.0",
]

[tool.ruff]
target-version = "py39"
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]

[tool.ruff.lint]
# E402: module level import not at top of file
# E501: line too long - let black worry about that
ignore = [
"E402",
"E501",
]
select = [
# Pyflakes
"F",
# Pycodestyle
"E",
"W",
# isort
"I",
# Pyupgrade
"UP",
]

[tool.ruff.lint.mccabe]
max-complexity = 18

[tool.ruff.lint.isort]
known-first-party = ["model_config_tests"]
6 changes: 0 additions & 6 deletions requirements.txt

This file was deleted.

Empty file.
Loading

0 comments on commit 809122d

Please sign in to comment.