From d27bfa49e16c43f311f8ce90f276ea057066d0c2 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Mon, 15 Apr 2019 14:02:57 +0100
Subject: [PATCH] TEST: Move some tests around

---
 tests/test_transform.py       | 50 ---------------------
 tests/test_transform_flirt.py | 85 +++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 50 deletions(-)
 create mode 100644 tests/test_transform_flirt.py

diff --git a/tests/test_transform.py b/tests/test_transform.py
index 70b86019a..442ceaa7d 100644
--- a/tests/test_transform.py
+++ b/tests/test_transform.py
@@ -500,56 +500,6 @@ def test_transformNormal(seed):
         assert np.all(np.isclose(expected, result))
 
 
-def test_flirtMatrixToSform():
-
-    testfile = op.join(datadir, 'test_transform_test_flirtMatrixToSform.txt')
-    lines    = readlines(testfile)
-    ntests   = len(lines) // 18
-
-    for i in range(ntests):
-        tlines    = lines[i * 18: i * 18 + 18]
-        srcShape  = [int(  w) for w in tlines[0].split()]
-        srcXform  = np.genfromtxt(tlines[1:5])
-        refShape  = [int(  w) for w in tlines[5].split()]
-        refXform  = np.genfromtxt(tlines[6:10])
-        flirtMat  = np.genfromtxt(tlines[10:14])
-        expected  = np.genfromtxt(tlines[14:18])
-
-        srcImg = fslimage.Image(np.zeros(srcShape), xform=srcXform)
-        refImg = fslimage.Image(np.zeros(refShape), xform=refXform)
-
-        result = transform.flirtMatrixToSform(flirtMat, srcImg, refImg)
-
-        assert np.all(np.isclose(result, expected))
-
-
-def test_sformToFlirtMatrix():
-    testfile = op.join(datadir, 'test_transform_test_flirtMatrixToSform.txt')
-    lines    = readlines(testfile)
-    ntests   = len(lines) // 18
-
-    for i in range(ntests):
-        tlines      = lines[i * 18: i * 18 + 18]
-        srcShape    = [int(  w) for w in tlines[0].split()]
-        srcXform    = np.genfromtxt(tlines[1:5])
-        refShape    = [int(  w) for w in tlines[5].split()]
-        refXform    = np.genfromtxt(tlines[6:10])
-        expected    = np.genfromtxt(tlines[10:14])
-        srcXformOvr = np.genfromtxt(tlines[14:18])
-
-        srcImg1 = fslimage.Image(np.zeros(srcShape), xform=srcXform)
-        srcImg2 = fslimage.Image(np.zeros(srcShape), xform=srcXform)
-        refImg  = fslimage.Image(np.zeros(refShape), xform=refXform)
-
-        srcImg2.voxToWorldMat = srcXformOvr
-
-        result1 = transform.sformToFlirtMatrix(srcImg1, refImg, srcXformOvr)
-        result2 = transform.sformToFlirtMatrix(srcImg2, refImg)
-
-        assert np.all(np.isclose(result1, expected))
-        assert np.all(np.isclose(result2, expected))
-
-
 def test_rmsdev():
 
     t1 = np.eye(4)
diff --git a/tests/test_transform_flirt.py b/tests/test_transform_flirt.py
new file mode 100644
index 000000000..2419cbbe2
--- /dev/null
+++ b/tests/test_transform_flirt.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+#
+# test_transform_flirt.py -
+#
+# Author: Paul McCarthy <pauldmccarthy@gmail.com>
+#
+
+import os.path as op
+
+import numpy as np
+
+import fsl.data.image as fslimage
+import fsl.utils.transform as transform
+import fsl.utils.tempdir   as tempdir
+
+from .test_transform import readlines
+
+
+datadir = op.join(op.dirname(__file__), 'testdata')
+
+
+def test_read_write():
+    with tempdir.tempdir():
+        aff = np.random.random((4, 4))
+        transform.writeFlirt(aff, 'aff.mat')
+        got = transform.readFlirt('aff.mat')
+        assert np.all(np.isclose(aff, got))
+
+
+def test_fromFlirt():
+    pass
+
+
+def test_toFlirt():
+    pass
+
+
+def test_flirtMatrixToSform():
+
+    testfile = op.join(datadir, 'test_transform_test_flirtMatrixToSform.txt')
+    lines    = readlines(testfile)
+    ntests   = len(lines) // 18
+
+    for i in range(ntests):
+        tlines    = lines[i * 18: i * 18 + 18]
+        srcShape  = [int(  w) for w in tlines[0].split()]
+        srcXform  = np.genfromtxt(tlines[1:5])
+        refShape  = [int(  w) for w in tlines[5].split()]
+        refXform  = np.genfromtxt(tlines[6:10])
+        flirtMat  = np.genfromtxt(tlines[10:14])
+        expected  = np.genfromtxt(tlines[14:18])
+
+        srcImg = fslimage.Image(np.zeros(srcShape), xform=srcXform)
+        refImg = fslimage.Image(np.zeros(refShape), xform=refXform)
+
+        result = transform.flirtMatrixToSform(flirtMat, srcImg, refImg)
+
+        assert np.all(np.isclose(result, expected))
+
+
+def test_sformToFlirtMatrix():
+    testfile = op.join(datadir, 'test_transform_test_flirtMatrixToSform.txt')
+    lines    = readlines(testfile)
+    ntests   = len(lines) // 18
+
+    for i in range(ntests):
+        tlines      = lines[i * 18: i * 18 + 18]
+        srcShape    = [int(  w) for w in tlines[0].split()]
+        srcXform    = np.genfromtxt(tlines[1:5])
+        refShape    = [int(  w) for w in tlines[5].split()]
+        refXform    = np.genfromtxt(tlines[6:10])
+        expected    = np.genfromtxt(tlines[10:14])
+        srcXformOvr = np.genfromtxt(tlines[14:18])
+
+        srcImg1 = fslimage.Image(np.zeros(srcShape), xform=srcXform)
+        srcImg2 = fslimage.Image(np.zeros(srcShape), xform=srcXform)
+        refImg  = fslimage.Image(np.zeros(refShape), xform=refXform)
+
+        srcImg2.voxToWorldMat = srcXformOvr
+
+        result1 = transform.sformToFlirtMatrix(srcImg1, refImg, srcXformOvr)
+        result2 = transform.sformToFlirtMatrix(srcImg2, refImg)
+
+        assert np.all(np.isclose(result1, expected))
+        assert np.all(np.isclose(result2, expected))
-- 
GitLab