diff --git a/nibabel/cifti2/tests/test_caretspec.py b/nibabel/cifti2/tests/test_caretspec.py new file mode 100644 index 0000000000..547d315aa3 --- /dev/null +++ b/nibabel/cifti2/tests/test_caretspec.py @@ -0,0 +1,18 @@ +from pathlib import Path + +from nibabel.cifti2.caretspec import * + +from nibabel.testing import data_path + + +def test_CaretSpecFile(): + fsLR = CaretSpecFile.from_filename(Path(data_path) / "fsLR.wb.spec") + + assert fsLR.metadata == {} + assert fsLR.version == "1.0" + assert len(fsLR.data_files) == 5 + + for df in fsLR.data_files: + assert isinstance(df, CaretSpecDataFile) + if df.data_file_type == 'SURFACE': + assert isinstance(df, SurfaceDataFile) diff --git a/nibabel/filebasedimages.py b/nibabel/filebasedimages.py index f7aecfb745..924bcac2a9 100644 --- a/nibabel/filebasedimages.py +++ b/nibabel/filebasedimages.py @@ -576,11 +576,13 @@ def to_bytes(self, **kwargs): return bio.getvalue() @classmethod - def from_url(klass, url): + def from_url(klass, url, timeout=5): """ Fetch image from remote location and construct an image Requires the ``requests`` library to be installed. """ import requests - res = requests.get(url) + res = requests.get(url, timeout=timeout) + if not res.ok: + raise IOError(f"[Error {res.status_code}] Could not retrieve {url}") return klass.from_bytes(res.content)