Skip to content
Snippets Groups Projects
Commit 49dd588f authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

TEST: More comprehensive tests for extract_noise

parent c6beb86d
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# Author: Paul McCarthy <pauldmccarthy@gmail.com> # Author: Paul McCarthy <pauldmccarthy@gmail.com>
# #
import sys
import numpy as np import numpy as np
...@@ -84,3 +85,73 @@ def test_loadConfoundFiles(): ...@@ -84,3 +85,73 @@ def test_loadConfoundFiles():
with pytest.raises(ValueError): with pytest.raises(ValueError):
extn.loadConfoundFiles(conffiles, npts) extn.loadConfoundFiles(conffiles, npts)
def test_extract_noise():
with tempdir.tempdir() as td:
# (npts, ncomps)
melmix = np.random.randint(1, 100, (100, 20))
np.savetxt('melodic_mix', melmix)
sys.argv = ['extract_noise', td] + '-o out.txt 1 2 3'.split()
extn.main()
assert np.all(np.loadtxt('out.txt') == melmix[:, :3])
with open('labels.txt', 'wt') as f:
f.write('4, 5, 6, 7')
extn.main([td] + '-o out.txt -ow 1 2 3 labels.txt'.split())
assert np.all(np.loadtxt('out.txt') == melmix[:, :7])
conf1 = np.random.randint(1, 100, (100, 1))
conf2 = np.random.randint(1, 100, (100, 5))
np.savetxt('conf1.txt', conf1)
np.savetxt('conf2.txt', conf2)
exp = np.hstack((melmix[:, :3], conf1, conf2))
extn.main([td] + '-o out.txt -c conf1.txt -c conf2.txt -ow 1 2 3'.split())
assert np.all(np.loadtxt('out.txt') == exp)
def test_extract_noise_usage():
with pytest.raises(SystemExit) as e:
extn.main([])
assert e.value.code == 0
def test_extract_noise_badargs():
with pytest.raises(SystemExit) as e:
extn.main(['non-existent.ica', '1', '2', '3'])
assert e.value.code != 0
with tempdir.tempdir() as td:
with pytest.raises(SystemExit) as e:
extn.main([td, 'non-existent.txt', '1', '2', '3'])
assert e.value.code != 0
with open('outfile.txt', 'wt') as f:
f.write('a')
# overwrite not specified
with pytest.raises(SystemExit) as e:
extn.main([td, '-o', 'outfile.txt', '1', '2', '3'])
assert e.value.code != 0
with pytest.raises(SystemExit) as e:
extn.main([td, '-c', 'non-existent.txt', '1', '2', '3'])
assert e.value.code != 0
# bad data
melmix = np.random.randint(1, 100, (100, 5))
np.savetxt('melodic_mix', melmix)
with open('labels.txt', 'wt') as f:
f.write('-1, 0, 1, 2')
with pytest.raises(SystemExit) as e:
extn.main([td, 'labels.txt', '1', '2', '3'])
assert e.value.code != 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment