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
da6d3389
Commit
da6d3389
authored
6 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Basic unit test for outprefix option
parent
35aa3ba7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/__init__.py
+8
-2
8 additions, 2 deletions
tests/__init__.py
tests/test_wrapperutils.py
+48
-1
48 additions, 1 deletion
tests/test_wrapperutils.py
with
56 additions
and
3 deletions
tests/__init__.py
+
8
−
2
View file @
da6d3389
...
...
@@ -11,8 +11,9 @@ import os
import
sys
import
glob
import
shutil
import
tempfile
import
fnmatch
import
logging
import
tempfile
import
contextlib
import
itertools
as
it
import
os.path
as
op
...
...
@@ -187,12 +188,17 @@ def make_dummy_image_file(path):
make_dummy_file
(
path
)
def
cleardir
(
dir
):
def
cleardir
(
dir
,
pat
=
None
):
"""
Deletes everything in the given directory, but not the directory
itself.
"""
for
f
in
os
.
listdir
(
dir
):
if
pat
is
not
None
and
not
fnmatch
.
fnmatch
(
f
,
pat
):
continue
f
=
op
.
join
(
dir
,
f
)
if
op
.
isfile
(
f
):
os
.
remove
(
f
)
elif
op
.
isdir
(
f
):
shutil
.
rmtree
(
f
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_wrapperutils.py
+
48
−
1
View file @
da6d3389
...
...
@@ -25,7 +25,7 @@ import fsl.data.image as fslimage
import
fsl.wrappers.wrapperutils
as
wutils
from
.
import
mockFSLDIR
from
.
import
mockFSLDIR
,
cleardir
from
.test_run
import
mock_submit
...
...
@@ -309,6 +309,53 @@ def test_fileOrImage():
assert
np
.
all
(
result
.
get_data
()[:]
==
expected
)
def
test_fileOrImage_outprefix
():
import
logging
logging
.
basicConfig
()
logging
.
getLogger
(
'
fsl.wrappers
'
).
setLevel
(
logging
.
DEBUG
)
@wutils.fileOrImage
(
'
img
'
,
outprefix
=
'
output_base
'
)
def
basefunc
(
img
,
output_base
):
img
=
nib
.
load
(
img
).
get_data
()
out1
=
nib
.
nifti1
.
Nifti1Image
(
img
*
5
,
np
.
eye
(
4
))
out2
=
nib
.
nifti1
.
Nifti1Image
(
img
*
10
,
np
.
eye
(
4
))
nib
.
save
(
out1
,
'
{}_times5.nii.gz
'
.
format
(
output_base
))
nib
.
save
(
out2
,
'
{}_times10.nii.gz
'
.
format
(
output_base
))
with
tempdir
.
tempdir
()
as
td
:
img
=
nib
.
nifti1
.
Nifti1Image
(
np
.
array
([[
1
,
2
],
[
3
,
4
]]),
np
.
eye
(
4
))
exp1
=
img
.
get_data
()
*
5
exp2
=
img
.
get_data
()
*
10
nib
.
save
(
img
,
'
img.nii
'
)
basefunc
(
'
img.nii
'
,
'
myout
'
)
assert
np
.
all
(
nib
.
load
(
'
myout_times5.nii.gz
'
)
.
get_data
()
==
exp1
)
assert
np
.
all
(
nib
.
load
(
'
myout_times10.nii.gz
'
).
get_data
()
==
exp2
)
cleardir
(
td
,
'
myout*
'
)
basefunc
(
img
,
'
myout
'
)
assert
np
.
all
(
nib
.
load
(
'
myout_times5.nii.gz
'
)
.
get_data
()
==
exp1
)
assert
np
.
all
(
nib
.
load
(
'
myout_times10.nii.gz
'
).
get_data
()
==
exp2
)
cleardir
(
td
,
'
myout*
'
)
res
=
basefunc
(
img
,
'
myout
'
,
myout_times5
=
wutils
.
LOAD
)
assert
np
.
all
(
res
[
'
myout_times5
'
].
get_data
()
==
exp1
)
cleardir
(
td
,
'
myout*
'
)
res
=
basefunc
(
img
,
'
myout
'
,
myout_times10
=
wutils
.
LOAD
)
assert
np
.
all
(
res
[
'
myout_times10
'
].
get_data
()
==
exp2
)
cleardir
(
td
,
'
myout*
'
)
res
=
basefunc
(
img
,
'
myout
'
,
myout
=
wutils
.
LOAD
)
assert
np
.
all
(
res
[
'
myout_times5
'
]
.
get_data
()
==
exp1
)
assert
np
.
all
(
res
[
'
myout_times10
'
].
get_data
()
==
exp2
)
cleardir
(
td
,
'
myout*
'
)
def
test_chained_fileOrImageAndArray
():
@wutils.fileOrImage
(
'
image
'
)
@wutils.fileOrArray
(
'
array
'
)
...
...
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