diff --git a/intake_thredds/source.py b/intake_thredds/source.py index 6370280..1ed3193 100644 --- a/intake_thredds/source.py +++ b/intake_thredds/source.py @@ -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'. @@ -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 diff --git a/tests/test_source.py b/tests/test_source.py index 473cc6d..1659023 100644 --- a/tests/test_source.py +++ b/tests/test_source.py @@ -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