Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fslpy
Commits
c9d7fff5
Commit
c9d7fff5
authored
Jun 02, 2022
by
Paul McCarthy
🚵
Browse files
TEST: Test pathlib support
parent
a428c3e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/test_ensure.py
View file @
c9d7fff5
...
...
@@ -5,6 +5,7 @@
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import
pathlib
import
numpy
as
np
import
nibabel
as
nib
...
...
@@ -22,8 +23,10 @@ def test_ensureIsImage():
assert
ensure
.
ensureIsImage
(
img
)
is
img
loaded
=
[
ensure
.
ensureIsImage
(
'image.nii'
),
ensure
.
ensureIsImage
(
'image'
)]
loaded
=
[
ensure
.
ensureIsImage
(
'image.nii'
),
ensure
.
ensureIsImage
(
'image'
),
ensure
.
ensureIsImage
(
pathlib
.
Path
(
'image'
)),
ensure
.
ensureIsImage
(
pathlib
.
Path
(
'image.nii'
))]
for
l
in
loaded
:
assert
isinstance
(
l
,
nib
.
nifti1
.
Nifti1Image
)
...
...
tests/test_wrappers/test_wrapperutils.py
View file @
c9d7fff5
...
...
@@ -475,6 +475,28 @@ def test_fileOrThing_outprefix():
cleardir
(
td
,
'myout*'
)
def
test_fileOrThing_pathlib
():
@
wutils
.
fileOrImage
(
'img'
,
outprefix
=
'output_base'
)
def
basefunc
(
img
,
output_base
):
img
=
np
.
asanyarray
(
nib
.
load
(
img
).
dataobj
)
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
=
np
.
asanyarray
(
img
.
dataobj
)
*
5
exp2
=
np
.
asanyarray
(
img
.
dataobj
)
*
10
nib
.
save
(
img
,
'img.nii'
)
basefunc
(
pathlib
.
Path
(
'img.nii'
),
pathlib
.
Path
(
'myout'
))
assert
np
.
all
(
np
.
asanyarray
(
nib
.
load
(
'myout_times5.nii.gz'
)
.
dataobj
)
==
exp1
)
assert
np
.
all
(
np
.
asanyarray
(
nib
.
load
(
'myout_times10.nii.gz'
).
dataobj
)
==
exp2
)
def
test_fileOrThing_outprefix_differentTypes
():
@
wutils
.
fileOrImage
(
'img'
,
outprefix
=
'outpref'
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment