From 20883ff74e5350d6cc29a36eb92e9819059ed667 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Tue, 27 Feb 2018 13:44:55 +0000
Subject: [PATCH] Unit test for MGHImage.save behaviour

---
 tests/test_mghimage.py | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/tests/test_mghimage.py b/tests/test_mghimage.py
index 513d0e762..752c5386d 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)
-- 
GitLab