From 15243a3f4462f2d02d56208a0028e5b8e8c75dcc Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Mon, 20 Jul 2020 11:32:24 +0100
Subject: [PATCH] TEST: test new imrm script

---
 tests/test_scripts/test_imrm.py | 50 +++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 tests/test_scripts/test_imrm.py

diff --git a/tests/test_scripts/test_imrm.py b/tests/test_scripts/test_imrm.py
new file mode 100644
index 000000000..ba7ff1c8d
--- /dev/null
+++ b/tests/test_scripts/test_imrm.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+#
+# test_imrm.py -
+#
+# Author: Paul McCarthy <pauldmccarthy@gmail.com>
+#
+
+import os
+
+from fsl.utils.tempdir import tempdir
+import fsl.scripts.imrm as imrm
+
+from tests import touch
+
+def test_imrm_usage():
+    assert imrm.main(['imrm']) != 0
+
+
+def test_imrm():
+    # (files present, command, expected)
+    tests = [
+        ('a.nii',       'a',       ''),
+        ('a.nii.gz',    'a',       ''),
+        ('a.img a.hdr', 'a',       ''),
+        ('a.img',       'a',       ''),
+        ('a.hdr',       'a',       ''),
+        ('a.nii b.nii', 'a',       'b.nii'),
+        ('a.nii b.nii', 'a b',     ''),
+        ('a.nii b.nii', 'a b.nii', ''),
+
+        # suffix doesn't have to be correct
+        ('a.nii.gz', 'a.nii',  ''),
+
+        # files don't exist -> no problem
+        ('a.nii', 'b',  'a.nii'),
+    ]
+
+    for files, command, expected in tests:
+        with tempdir():
+
+            for f in files.split():
+                touch(f)
+
+            print('files',    files)
+            print('command',  command)
+            print('expected', expected)
+
+            imrm.main(('imrm ' + command).split())
+
+            assert sorted(os.listdir()) == sorted(expected.split())
-- 
GitLab