Skip to content
Snippets Groups Projects
Commit d7639631 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Unit tests for callfsl module

parent b6e55df8
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
#
# test_callfsl.py -
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import os
import os.path as op
import subprocess as sp
import numpy as np
import pytest
import fsl.utils.callfsl as callfsl
from fsl.utils.platform import platform as fslplatform
import tests
def setup_module():
fsldir = os.environ.get('FSLDIR', None)
if fsldir is None or not op.exists(fsldir):
raise Exception('FSLDIR is not set - callfsl tests cannot be run')
def test_callfsl():
with tests.testdir() as testdir:
fname = op.join(testdir, 'myimage.nii.gz')
img = tests.make_random_image(fname)
img = img.get_data()
# Pass a single string
cmd = 'fslstats {} -m'.format(fname)
result = callfsl.callFSL(cmd)
assert np.isclose(float(result), img.mean())
# Or pass a list of args
result = callfsl.callFSL(*cmd.split())
assert np.isclose(float(result), img.mean())
# Bad commands
badcmds = ['fslblob', 'fslstats notafile']
for cmd in badcmds:
with pytest.raises((OSError, sp.CalledProcessError)):
callfsl.callFSL(cmd)
# No FSL - should crash
cmd = 'fslinfo {}'.format(fname)
callfsl.callFSL(cmd)
fslplatform.fsldir = None
with pytest.raises(Exception):
callfsl.callFSL(cmd)
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