def test_uri_to_local_path(): if os.name == 'nt': assert 'C:\\tmp\\test.tmp' == str( uri_to_local_path('file:///C:/tmp/test.tmp')) else: assert '/tmp/something.txt' == str( uri_to_local_path('file:///tmp/something.txt')) assert uri_to_local_path(None) is None with pytest.raises(ValueError): uri_to_local_path('ftp://example.com/tmp/something.txt')
def load_documents(path): """ Load document/s from the specified path. At the moment can handle: - JSON and YAML locally and remotely. - Compressed JSON and YAML locally - Data Cube Dataset Documents inside local NetCDF files. :param path: path or URI to load documents from :return: generator of dicts """ path = str(path) url = as_url(path) scheme = urlparse(url).scheme compressed = url[-3:] == '.gz' if scheme == 'file' and path[-3:] == '.nc': path = uri_to_local_path(url) yield from load_from_netcdf(path) else: with _PROTOCOL_OPENERS[scheme](url) as fh: if compressed: fh = gzip.open(fh) path = path[:-3] suffix = Path(path).suffix parser = _PARSERS[suffix] yield from parser(fh)