From ab081206e47de8170c9d12c18e0928937af6ac6f Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Wed, 12 Apr 2017 11:17:01 +0100
Subject: [PATCH] Bug in image module test

---
 tests/test_image.py | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/tests/test_image.py b/tests/test_image.py
index 938b5821f..19f7eea86 100644
--- a/tests/test_image.py
+++ b/tests/test_image.py
@@ -876,6 +876,16 @@ def _test_Image_save(imgtype):
         return (np.random.randint(0, 10),
                 np.random.randint(0, 10),
                 np.random.randint(0, 10))
+
+    def randvoxes(num):
+        rvoxes = []
+
+        while len(rvoxes) < num:
+            rvox = randvox()
+            if rvox not in rvoxes:
+                rvoxes.append(rvox)
+        return rvoxes
+        
     
     testdir   = tempfile.mkdtemp()
     if imgtype == 0:
@@ -896,7 +906,7 @@ def _test_Image_save(imgtype):
 
         img = fslimage.Image(filename)
 
-        randvoxes = [randvox()          for i in range(5)]
+        randvoxes = randvoxes(5)
         randvals  = [np.random.random() for i in range(5)]
         
         for (x, y, z), v in zip(randvoxes, randvals):
@@ -925,5 +935,18 @@ def _test_Image_save(imgtype):
             for (x, y, z), v in zip(randvoxes, randvals):
                 assert np.isclose(img[x, y, z], v)
 
+            # Load the image back in
+            img2 = fslimage.Image(img.dataSource)
+            
+            assert img.saveState
+            assert img.dataSource == expDataSource
+
+            if imgtype > 0:
+                assert np.all(np.isclose(img.voxToWorldMat, xform))
+
+            for (x, y, z), v in zip(randvoxes, randvals):
+                assert np.isclose(img[x, y, z], v) 
+            
+
     finally:
         shutil.rmtree(testdir)
-- 
GitLab