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

TEST: Unit test for fsldir/fsldevdir/fsl_prefix

parent f7bf82cb
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
import os.path as op import os.path as op
import os import os
import shutil
import textwrap import textwrap
# python 3 # python 3
...@@ -161,11 +162,13 @@ def test_runfsl(): ...@@ -161,11 +162,13 @@ def test_runfsl():
test_script = textwrap.dedent(""" test_script = textwrap.dedent("""
#!/bin/bash #!/bin/bash
echo $@ echo {}
exit 0 exit 0
""").strip() """).strip()
old_fsldir = fslplatform.fsldir old_fsldir = fslplatform.fsldir
old_fsldevdir = fslplatform.fsldevdir
try: try:
with tempdir.tempdir(): with tempdir.tempdir():
...@@ -173,24 +176,51 @@ def test_runfsl(): ...@@ -173,24 +176,51 @@ def test_runfsl():
make_random_image('image.nii.gz') make_random_image('image.nii.gz')
# no FSLDIR - should error # no FSLDIR - should error
fslplatform.fsldir = None fslplatform.fsldir = None
fslplatform.fsldevdir = None
with pytest.raises(run.FSLNotPresent): with pytest.raises(run.FSLNotPresent):
run.runfsl('fslhd image') run.runfsl('fslhd')
# FSLDIR/bin exists - should be good # FSLDIR/bin exists - should be good
fsldir = op.abspath('./fsl') fsldir = op.abspath('./fsl')
fslhd = op.join(fsldir, 'bin', 'fslhd') fslhd = op.join(fsldir, 'bin', 'fslhd')
os.makedirs(op.join(fsldir, 'bin')) os.makedirs(op.join(fsldir, 'bin'))
with open(fslhd, 'wt') as f: with open(fslhd, 'wt') as f:
f.write(test_script) f.write(test_script.format('fsldir'))
os.chmod(fslhd, 0o777) os.chmod(fslhd, 0o777)
fslplatform.fsldir = fsldir fslplatform.fsldir = fsldir
path = op.pathsep.join((fsldir, os.environ['PATH'])) assert run.runfsl('fslhd').strip() == 'fsldir'
with mock.patch.dict(os.environ, {'PATH' : path}):
assert run.runfsl('fslhd image').strip() == 'image' # FSLDEVDIR should take precedence
fsldevdir = './fsldev'
fslhd = op.join(fsldevdir, 'bin', 'fslhd')
shutil.copytree(fsldir, fsldevdir)
with open(fslhd, 'wt') as f:
f.write(test_script.format('fsldevdir'))
fslplatform.fsldevdir = fsldevdir
fslplatform.fsldir = None
assert run.runfsl('fslhd').strip() == 'fsldevdir'
# FSL_PREFIX should override all
override = './override'
fslhd = op.join(override, 'fslhd')
os.makedirs(override)
with open(fslhd, 'wt') as f:
f.write(test_script.format('override'))
os.chmod(fslhd, 0o777)
fslplatform.fsldir = None
fslplatform.fsldevdir = None
run.FSL_PREFIX = override
assert run.runfsl('fslhd').strip() == 'override'
finally: finally:
fslplatform.fsldir = old_fsldir fslplatform.fsldir = old_fsldir
fslplatform.fsldevdir = old_fsldevdir
run.FSL_PREFIX = None
def mock_submit(cmd, **kwargs): def mock_submit(cmd, **kwargs):
......
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