Skip to content

Commit

Permalink
check type of path (#63)
Browse files Browse the repository at this point in the history
Co-authored-by: Anderson Banihirwe <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 12, 2022
1 parent 27b31a2 commit 2a699a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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

0 comments on commit 2a699a4

Please sign in to comment.