Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check type of path #63

Merged
merged 20 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion intake_thredds/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class THREDDSMergedSource(DataSourceMixin):
----------
url : str
Location of server
path : list of str
path : str, list of str
Subcats to follow; include glob characters (*, ?) in here for matching.
driver : str
Select driver to access data. Choose from 'netcdf' and 'opendap'.
Expand Down Expand Up @@ -69,6 +69,12 @@ def __init__(
self.urlpath = url
if 'simplecache::' in url:
self.metadata.update({'fsspec_pre_url': 'simplecache::'})
if isinstance(path, str):
path = [path]
if not isinstance(path, list):
raise ValueError(f'path must be list of str, found {type(path)}')
if not all(isinstance(item, str) for item in path):
raise ValueError('path must be list of str')
self.path = path
self.driver = driver
self.xarray_kwargs = xarray_kwargs
Expand Down
12 changes: 12 additions & 0 deletions tests/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ def THREDDSMergedSource_cat_short(
return cat


@pytest.mark.parametrize('path', [1, [1, 'air.sig995.194*.nc']])
def test_THREDDSMergedSource_path_error(THREDDSMergedSource_cat_short_url, path):
with pytest.raises(ValueError):
intake.open_thredds_merged(THREDDSMergedSource_cat_short_url, path)


@pytest.mark.parametrize('path', ['air.sig995.194*.nc', ['air.sig995.194*.nc']])
def test_THREDDSMergedSource_path(THREDDSMergedSource_cat_short_url, path):
"""THREDDSMergedSource for various types of path."""
assert intake.open_thredds_merged(THREDDSMergedSource_cat_short_url, path)


@pytest.fixture(scope='module')
def THREDDSMergedSource_cat_short_simplecache(
THREDDSMergedSource_cat_short_url, THREDDSMergedSource_cat_short_path
Expand Down