Skip to content

Commit ce210bd

Browse files
committed
TEST: Validate DataobjImage.ndim
1 parent d2d07d4 commit ce210bd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

nibabel/tests/test_image_api.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def validate_data_interface(self, imaker, params):
202202
# Check get data returns array, and caches
203203
img = imaker()
204204
assert_equal(img.shape, img.dataobj.shape)
205-
assert_equal(len(img.shape), img.dataobj.ndim)
205+
assert_equal(img.ndim, len(img.shape))
206206
assert_data_similar(img.dataobj, params)
207207
for meth_name in self.meth_names:
208208
if params['is_proxy']:
@@ -211,6 +211,8 @@ def validate_data_interface(self, imaker, params):
211211
self._check_array_interface(imaker, meth_name)
212212
# Data shape is same as image shape
213213
assert_equal(img.shape, getattr(img, meth_name)().shape)
214+
# Data ndim is same as image ndim
215+
assert_equal(img.ndim, getattr(img, meth_name)().ndim)
214216
# Values to get_data caching parameter must be 'fill' or
215217
# 'unchanged'
216218
assert_raises(ValueError, img.get_data, caching='something')
@@ -395,6 +397,17 @@ def validate_shape(self, imaker, params):
395397
# Read only
396398
assert_raises(AttributeError, setattr, img, 'shape', np.eye(4))
397399

400+
def validate_ndim(self, imaker, params):
401+
# Validate shape
402+
img = imaker()
403+
# Same as expected ndim
404+
assert_equal(img.ndim, len(params['shape']))
405+
# Same as array ndim if passed
406+
if 'data' in params:
407+
assert_equal(img.ndim, params['data'].ndim)
408+
# Read only
409+
assert_raises(AttributeError, setattr, img, 'ndim', 5)
410+
398411
def validate_shape_deprecated(self, imaker, params):
399412
# Check deprecated get_shape API
400413
img = imaker()

0 commit comments

Comments
 (0)