-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f70600d
commit c006ebc
Showing
4 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |