diff --git a/.github/workflows/mopper-test-calcs.yaml b/.github/workflows/mopper-test-calcs.yaml new file mode 100644 index 0000000..50d2512 --- /dev/null +++ b/.github/workflows/mopper-test-calcs.yaml @@ -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 + #--------------------------------------------------- diff --git a/conda/environment.yaml b/conda/environment.yaml new file mode 100644 index 0000000..2f0d566 --- /dev/null +++ b/conda/environment.yaml @@ -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 diff --git a/src/mopper/calculations.py b/src/mopper/calculations.py index d217aef..f35a516 100644 --- a/src/mopper/calculations.py +++ b/src/mopper/calculations.py @@ -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 #---------------------------------------------------------------------- diff --git a/tests/conftest.py b/tests/conftest.py index 0dd6c56..f26c225 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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__)) @@ -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): diff --git a/tests/test_calculations.py b/tests/test_calculations.py index 9037b53..dc8507b 100644 --- a/tests/test_calculations.py +++ b/tests/test_calculations.py @@ -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 @@ -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') @@ -118,3 +118,4 @@ def test_overturn_stream(caplog): with ctx: out4 = overturn_stream(varlist) nptest.assert_array_equal(res4, out4) +'''