Skip to content

Commit 0507393

Browse files
committed
TST: Make sure that img.__getitem__ exception throws the right error.
For a reasonable use-case.
1 parent 82a261c commit 0507393

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

nibabel/tests/test_spatialimages.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,15 @@ def test_get_data(self):
312312
in_data_template = np.arange(24, dtype=np.int16).reshape((2, 3, 4))
313313
in_data = in_data_template.copy()
314314
img = img_klass(in_data, None)
315+
# Can't slice into the image object:
316+
with assert_raises(TypeError) as exception_manager:
317+
img[0, 0, 0]
318+
319+
assert_equal(str(exception_manager.exception),
320+
("Cannot slice image objects; consider slicing image "
321+
"array data with `img.dataobj[slice]` or "
322+
"`img.get_data()[slice]`"))
323+
315324
assert_true(in_data is img.dataobj)
316325
out_data = img.get_data()
317326
assert_true(in_data is out_data)

0 commit comments

Comments
 (0)