Skip to content
Snippets Groups Projects
Commit 20883ff7 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Unit test for MGHImage.save behaviour

parent fb4b597a
No related branches found
No related tags found
No related merge requests found
......@@ -7,18 +7,21 @@
import os.path as op
import shutil
import numpy as np
import nibabel as nib
from . import testdir
import fsl.utils.tempdir as tempdir
import fsl.data.mghimage as fslmgh
import fsl.data.image as fslimage
datadir = op.join(op.abspath(op.dirname(__file__)), 'testdata')
def test_MGHImage():
datadir = op.join(op.dirname(__file__), 'testdata')
testfile = op.join(datadir, 'example.mgz')
# Load from a file
......@@ -27,10 +30,32 @@ def test_MGHImage():
assert np.all(np.isclose(img[:], nbimg.get_data()))
assert np.all(np.isclose(img.voxToWorldMat, nbimg.affine))
assert img.name == op.basename(testfile)
assert img.dataSource == testfile
assert img.mghImageFile == testfile
# Load from an in-memory nibabel object
img = fslmgh.MGHImage(nbimg)
assert np.all(np.isclose(img[:], nbimg.get_data()))
assert np.all(np.isclose(img.voxToWorldMat, nbimg.affine))
assert img.dataSource is None
assert img.mghImageFile is None
def test_MGHImage_save():
testfile = op.join(datadir, 'example.mgz')
with tempdir.tempdir():
shutil.copy(testfile, 'example.mgz')
testfile = 'example.mgz'
img = fslmgh.MGHImage(testfile)
img.save()
expfile = op.abspath(fslimage.addExt('example', mustExist=False))
assert img.dataSource == op.abspath(expfile)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment