Skip to content

Commit

Permalink
test and document changes
Browse files Browse the repository at this point in the history
  • Loading branch information
observingClouds committed Oct 31, 2024
1 parent f70600d commit c006ebc
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
11 changes: 10 additions & 1 deletion .github/workflows/python-package-pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ jobs:
python -m pip install .
python -m pip install pytest
- name: Run tests
- name: Run tests (non-distributed)
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
python -m pytest tests/
- name: Install distributed dependencies
run: |
python -m pip install .[dask-distributed]
- name: Run tests (distributed)
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- add support for CLI calls. ![\25](https://github.com/mllam/mllam-data-prep/pull/25).
- add optional output path argument to parser. ![\#26](https://github.com/mllam/mllam-data-prep/pull/26)

### Changed
Expand All @@ -18,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- fix typo in install dependency `distributed` ![\#20](https://github.com/mllam/mllam-data-prep/pull/20)
- add missing `psutil` requirement. [\#21](https://github.com/mllam/mllam-data-prep/pull/21).


## [v0.3.0](https://github.com/mllam/mllam-data-prep/releases/tag/v0.3.0)

[All changes](https://github.com/mllam/mllam-data-prep/compare/v0.3.0...v0.2.0)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import tempfile

import pytest
import xarray as xr

from mllam_data_prep.cli import call


@pytest.mark.parametrize("args", [["example.danra.yaml"]])
def test_call(args):
with tempfile.TemporaryDirectory(suffix=".zarr") as tmpdir:
args.extend(["--output", tmpdir])
call(args)
_ = xr.open_zarr(tmpdir)
53 changes: 53 additions & 0 deletions tests/test_distributed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import importlib
import tempfile

import pytest
import xarray as xr

from mllam_data_prep.cli import call


def call_wrapper(args):
with tempfile.TemporaryDirectory(suffix=".zarr") as tmpdir:
args.extend(["--output", tmpdir])
call(args)
_ = xr.open_zarr(tmpdir)


def distributed():
"""Check if dask.distributed is installed"""
try:
importlib.import_module("dask.distributed")

return True
except (ModuleNotFoundError, ImportError):
return False


@pytest.mark.parametrize(
"args",
[
["example.danra.yaml", "--dask-distributed-local-core-fraction", "1.0"],
["example.danra.yaml"],
],
)
def test_run_distributed(args):
if distributed():
call_wrapper(args)
elif not distributed() and "--dask-distributed-local-core-fraction" in args:
index = args.index("--dask-distributed-local-core-fraction")
core_fraction = float(args[index + 1])
if core_fraction > 0:
pytest.raises(
NameError,
call_wrapper,
args=args,
)
else:
pytest.raises(
ModuleNotFoundError,
call_wrapper,
args=args,
)
else:
call_wrapper(args)

0 comments on commit c006ebc

Please sign in to comment.