From 42e712e0b995f81d32e240290d2d6c061745a999 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Sat, 20 Aug 2022 15:16:49 -0400 Subject: [PATCH] TEST: Check SurfaceDataFile retrieval --- nibabel/cifti2/tests/test_caretspec.py | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 nibabel/cifti2/tests/test_caretspec.py diff --git a/nibabel/cifti2/tests/test_caretspec.py b/nibabel/cifti2/tests/test_caretspec.py new file mode 100644 index 000000000..604808c3f --- /dev/null +++ b/nibabel/cifti2/tests/test_caretspec.py @@ -0,0 +1,34 @@ +import unittest +from pathlib import Path + +from nibabel.cifti2.caretspec import * +from nibabel.optpkg import optional_package +from nibabel.testing import data_path + +requests, has_requests, _ = optional_package('requests') + + +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) + + +@unittest.skipUnless(has_requests, reason='Test fetches from URL') +def test_SurfaceDataFile(): + fsLR = CaretSpecFile.from_filename(Path(data_path) / 'fsLR.wb.spec') + df = fsLR.data_files[0] + assert df.data_file_type == 'SURFACE' + try: + coords, triangles = df.get_mesh() + except IOError: + raise unittest.SkipTest(reason='Broken URL') + assert coords.shape == (32492, 3) + assert triangles.shape == (64980, 3)