Skip to content

Commit

Permalink
merged pytests_sam in preprelease
Browse files Browse the repository at this point in the history
  • Loading branch information
paolap committed Jul 16, 2024
2 parents 357e4e9 + 8fa654c commit f1c6790
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 10 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/mopper-test-calcs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: mopper-conda-install-test

#on: [push]
on:
push:
branches:
- pytests_sam


jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 5
matrix:
python-version: ["3.10"]


steps:
- uses: actions/checkout@v4
#---------------------------------------------------
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
#---------------------------------------------------
# Install Miniconda
- name: Install Miniconda
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}

# Create and activate conda environment
- name: Create and activate conda environment
run: |
conda env create --name test-env --file conda/environment.yaml
# Install dependencies from conda
- name: Install dependencies
run: conda env update --name test-env --file conda/environment.yaml
#---------------------------------------------------
#- name: Lint with flake8
# run: |
# conda install flake8
# stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# - name: Install package
# run: |
# conda build conda/meta.yaml
#---------------------------------------------------
- name: Test with pytest
run: |
conda install -n test-env pytest coverage codecov
conda run -n test-env pytest -q tests/test_calculations.py
# conda run -n test-env coverage run --source src -m pytest
#---------------------------------------------------
#- name: Upload to codecov
# if: steps.build.outcome == 'success'
# run: |
# curl -Os https://uploader.codecov.io/latest/linux/codecov
# chmod +x codecov
# ./codecov
#---------------------------------------------------
22 changes: 22 additions & 0 deletions conda/environment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: test-env
channels:
- defaults
- conda-forge
dependencies:
- python=3.10
- pip
- pbr
- click
- cmor
- xarray
- numpy
- dask
- pyyaml
- cftime
- python-dateutil
- pytest
- coverage
- codecov
- importlib_resources
- pip:
- git+https://github.com/ACCESS-Community-Hub/ACCESS-MOPPeR@pytests_sam
2 changes: 1 addition & 1 deletion src/mopper/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ def calc_topsoil(soilvar):
# calculate the fraction of maxlev which falls in first 10cm
fraction = (0.1 - depth[maxlev -1])/(depth[maxlev] - depth[maxlev-1])
topsoil = soilvar.isel(depth=slice(0,maxlev)).sum(dim='depth')
topsoil = topsoil + fraction * topsoil.isel(depth=maxlev)
topsoil = topsoil + fraction * soilvar.isel(depth=maxlev)

return topsoil
#----------------------------------------------------------------------
Expand Down
14 changes: 7 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import logging
import csv
from mopdb.mopdb_utils import mapping_sql, cmorvar_sql
from mopper.setup_utils import filelist_sql
#from mopper.setup_utils import filelist_sql


TESTS_HOME = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -59,12 +59,12 @@ def setup_access_db(session):
session.connection.commit()


@pytest.fixture
def setup_mopper_db(session):
filelist_sql = mapping_sql()
session.execute(filelist_sql)
session.execute('''INSERT INTO filelist VALUES ("/testdata/atmos/umnsa_spec_*.nc", "/testdata/mjo-elnino/v1-0/A10min/", "tas_AUS2200_mjo-elnino_subhrPt_20160101001000-20160102000000.nc", "fld_s03i236", "tas", "AUS2200_A10min", "subhrPt", "atmos", "point", "20160101T0005", "20160102T0000", "201601010000", "201601012355", "unprocessed", "3027.83203125", "mjo-elnino", "K", "AUS2200", "AUS2200", "/testdata/mjo-elnino/mjo-elnino.json", "1970-01-01", "v1-0")''')
session.connection.commit()
#@pytest.fixture
#def setup_mopper_db(session):
# filelist_sql = mapping_sql()
# session.execute(filelist_sql)
# session.execute('''INSERT INTO filelist VALUES ("/testdata/atmos/umnsa_spec_*.nc", "/testdata/mjo-elnino/v1-0/A10min/", "tas_AUS2200_mjo-elnino_subhrPt_20160101001000-20160102000000.nc", "fld_s03i236", "tas", "AUS2200_A10min", "subhrPt", "atmos", "point", "20160101T0005", "20160102T0000", "201601010000", "201601012355", "unprocessed", "3027.83203125", "mjo-elnino", "K", "AUS2200", "AUS2200", "/testdata/mjo-elnino/mjo-elnino.json", "1970-01-01", "v1-0")''')
# session.connection.commit()


def test_check_timestamp(caplog):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def create_var(nlat, nlon, ntime=None, nlev=None, sdepth=False, seed=100):
dims.insert(0, 'lev')
coords['lev'] = lev
shape.insert(0, nlev)
elif sdepth is True:
if sdepth is True:
depth = np.array([0.05, 0.2, 0.5, 1])
dims.insert(0, 'depth')
coords['depth'] = depth
Expand All @@ -66,7 +66,7 @@ def test_calc_topsoil():
out = calc_topsoil(mrsol)
xrtest.assert_allclose(out, expected, rtol=1e-05)


'''
def test_overturn_stream(caplog):
global ctx
caplog.set_level(logging.DEBUG, logger='varlog_1')
Expand Down Expand Up @@ -118,3 +118,4 @@ def test_overturn_stream(caplog):
with ctx:
out4 = overturn_stream(varlist)
nptest.assert_array_equal(res4, out4)
'''

0 comments on commit f1c6790

Please sign in to comment.