-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI tests for Dask client parallelization method
- httpstore._mfprocessor_json no longer raises DataNotFound
- Loading branch information
Showing
6 changed files
with
158 additions
and
5 deletions.
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
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,139 @@ | ||
import pytest | ||
import logging | ||
|
||
from dask.distributed import Client | ||
from argopy import DataFetcher | ||
from collections import ChainMap | ||
import xarray as xr | ||
|
||
from mocked_http import mocked_server_address, mocked_httpserver | ||
|
||
|
||
log = logging.getLogger("argopy.tests.dask") | ||
USE_MOCKED_SERVER = True | ||
|
||
""" | ||
List data sources to be tested | ||
""" | ||
SRC_LIST = ["erddap", "argovis", "gdac"] | ||
|
||
|
||
""" | ||
List access points to be tested for each datasets: phy. | ||
For each access points, we list 1-to-2 scenario to make sure all possibilities are tested | ||
""" | ||
PARALLEL_ACCESS_POINTS = [ | ||
{ | ||
"phy": [ | ||
{"region": [-60, -55, 40.0, 45.0, 0.0, 20.0, "2007-08-01", "2007-09-01"]}, | ||
] | ||
}, | ||
] | ||
|
||
""" | ||
List user modes to be tested | ||
""" | ||
USER_MODES = ["standard"] # Because it's the only available with argovis | ||
|
||
""" | ||
Make a list of VALID dataset/access_points to be tested | ||
""" | ||
VALID_PARALLEL_ACCESS_POINTS, VALID_PARALLEL_ACCESS_POINTS_IDS = [], [] | ||
for entry in PARALLEL_ACCESS_POINTS: | ||
for src in SRC_LIST: | ||
for ds in entry: | ||
for mode in USER_MODES: | ||
for ap in entry[ds]: | ||
VALID_PARALLEL_ACCESS_POINTS.append( | ||
{"src": src, "ds": ds, "mode": mode, "access_point": ap} | ||
) | ||
VALID_PARALLEL_ACCESS_POINTS_IDS.append( | ||
"src='%s', ds='%s', mode='%s', %s" % (src, ds, mode, ap) | ||
) | ||
|
||
|
||
def create_fetcher(fetcher_args, access_point): | ||
"""Create a fetcher for a given set of facade options and access point""" | ||
|
||
def core(fargs, apts): | ||
try: | ||
f = DataFetcher(**fargs) | ||
if "float" in apts: | ||
f = f.float(apts["float"]) | ||
elif "profile" in apts: | ||
f = f.profile(*apts["profile"]) | ||
elif "region" in apts: | ||
f = f.region(apts["region"]) | ||
except Exception: | ||
raise | ||
return f | ||
|
||
fetcher = core(fetcher_args, access_point) | ||
return fetcher | ||
|
||
|
||
class Test_Backend: | ||
"""Test Dask cluster parallelization""" | ||
|
||
############# | ||
# UTILITIES # | ||
############# | ||
def setup_class(self): | ||
"""setup any state specific to the execution of the given class""" | ||
# Create the cache folder here, so that it's not the same for the pandas and pyarrow tests | ||
self.client = Client(processes=True) | ||
log.debug(self.client.dashboard_link) | ||
|
||
def _test2fetcherargs(self, this_request): | ||
"""Helper method to set up options for a fetcher creation""" | ||
defaults_args = { | ||
"parallel": self.client, | ||
"chunks_maxsize": {"lon": 2.5, "lat": 2.5}, | ||
} | ||
if USE_MOCKED_SERVER: | ||
defaults_args["server"] = mocked_server_address | ||
|
||
src = this_request.param["src"] | ||
dataset = this_request.param["ds"] | ||
user_mode = this_request.param["mode"] | ||
access_point = this_request.param["access_point"] | ||
|
||
fetcher_args = ChainMap( | ||
defaults_args, | ||
{ | ||
"src": src, | ||
"ds": dataset, | ||
"mode": user_mode, | ||
}, | ||
) | ||
|
||
# log.debug("Setting up fetcher arguments:%s" % fetcher_args) | ||
return fetcher_args, access_point | ||
|
||
@pytest.fixture | ||
def fetcher(self, request): | ||
"""Fixture to create a data fetcher for a given dataset and access point""" | ||
fetcher_args, access_point = self._test2fetcherargs(request) | ||
yield create_fetcher(fetcher_args, access_point) | ||
|
||
def teardown_class(self): | ||
"""Cleanup once we are finished.""" | ||
self.client.close() | ||
|
||
######### | ||
# TESTS # | ||
######### | ||
@pytest.mark.parametrize( | ||
"fetcher", | ||
VALID_PARALLEL_ACCESS_POINTS, | ||
indirect=True, | ||
ids=VALID_PARALLEL_ACCESS_POINTS_IDS, | ||
) | ||
def test_fetching_erddap(self, mocked_httpserver, fetcher): | ||
# log.debug(fetcher) | ||
# log.debug(len(fetcher.uri)) | ||
# log.debug(fetcher.uri) | ||
assert len(fetcher.uri) > 1 | ||
|
||
ds = fetcher.to_xarray() | ||
assert isinstance(ds, xr.Dataset) |