Skip to content

Commit

Permalink
Merge pull request #1221 from effigies/fix/test-slicing
Browse files Browse the repository at this point in the history
FIX: Catch random bad slice when testing image slicing
  • Loading branch information
effigies authored Apr 4, 2023
2 parents e221d77 + 8bb1b99 commit d4cf55f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions nibabel/tests/test_spatialimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,15 +540,15 @@ def test_slicer(self):
sliceobj = tuple(np.random.choice(slice_elems, n_elems))
try:
sliced_img = img.slicer[sliceobj]
except (IndexError, ValueError):
# Only checking valid slices
pass
else:
sliced_data = in_data[sliceobj]
assert (sliced_data == sliced_img.get_fdata()).all()
assert (sliced_data == sliced_img.dataobj).all()
assert (sliced_data == img.dataobj[sliceobj]).all()
assert (sliced_data == img.get_fdata()[sliceobj]).all()
except (IndexError, ValueError, HeaderDataError):
# Skip invalid slices or images that can't be created
continue

sliced_data = in_data[sliceobj]
assert np.array_equal(sliced_data, sliced_img.get_fdata())
assert np.array_equal(sliced_data, sliced_img.dataobj)
assert np.array_equal(sliced_data, img.dataobj[sliceobj])
assert np.array_equal(sliced_data, img.get_fdata()[sliceobj])


class MmapImageMixin:
Expand Down

0 comments on commit d4cf55f

Please sign in to comment.