Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
d7639631
Commit
d7639631
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Unit tests for callfsl module
parent
b6e55df8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_callfsl.py
+57
-0
57 additions, 0 deletions
tests/test_callfsl.py
with
57 additions
and
0 deletions
tests/test_callfsl.py
0 → 100644
+
57
−
0
View file @
d7639631
#!/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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment