diff --git a/tests/test_mghimage.py b/tests/test_mghimage.py index 513d0e7623822b6ec5c21f28cbfcb54a62577b20..752c5386d2b76f3a9c90ad161fd91d4890701428 100644 --- a/tests/test_mghimage.py +++ b/tests/test_mghimage.py @@ -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)