Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD 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
FSL
fslpy
Commits
aadde34d
Commit
aadde34d
authored
8 months ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Unit tests for loadFTests and getZFStatFile functions
parent
7bf987d4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/tests/test_featanalysis.py
+118
-0
118 additions, 0 deletions
fsl/tests/test_featanalysis.py
with
118 additions
and
0 deletions
fsl/tests/test_featanalysis.py
+
118
−
0
View file @
aadde34d
...
@@ -210,6 +210,77 @@ def test_loadContrasts():
...
@@ -210,6 +210,77 @@ def test_loadContrasts():
featanalysis
.
loadContrasts
(
featdir
)
featanalysis
.
loadContrasts
(
featdir
)
def
test_loadFTests
():
goodtests
=
[
(
"""
/NumWaves 4
/NumContrasts 3
/Matrix
0 1 0 1
0 0 1 1
1 1 1 1
"""
,
[[
0
,
1
,
0
,
1
],
[
0
,
0
,
1
,
1
],
[
1
,
1
,
1
,
1
]]),
(
"""
/NumWaves 10
/NumContrasts 2
/Matrix
0 1 0 1 0 1 1 0 0 1
0 0 1 1 1 0 0 1 0 0
"""
,
[[
0
,
1
,
0
,
1
,
0
,
1
,
1
,
0
,
0
,
1
],
[
0
,
0
,
1
,
1
,
1
,
0
,
0
,
1
,
0
,
0
]]),
]
badtests
=
[
"""
/NumWaves 10
/NumContrasts 2
"""
,
"""
/NumContrasts 2
/Matrix
1 0
0 1
"""
,
"""
/NumWaves Burgers
/NumContrasts 2
/Matrix
1 0
0 1
"""
,
"""
/Matrix
1 0
0 1
"""
,
"""
/NumWaves 4
/NumContrasts 3
/Matrix
1 0 0 0 1 0 0
0 1 0 0 1 0 0
"""
,
]
with
tests
.
testdir
()
as
testdir
:
featdir
=
op
.
join
(
testdir
,
'
analysis.feat
'
)
for
contents
,
expect
in
goodtests
:
designcon
=
op
.
join
(
featdir
,
'
design.fts
'
)
tests
.
make_dummy_file
(
designcon
,
textwrap
.
dedent
(
contents
).
strip
())
assert
featanalysis
.
loadFTests
(
featdir
)
==
expect
for
contents
in
badtests
:
designcon
=
op
.
join
(
featdir
,
'
design.fts
'
)
tests
.
make_dummy_file
(
designcon
,
textwrap
.
dedent
(
contents
).
strip
())
with
pytest
.
raises
(
Exception
):
featanalysis
.
loadFTests
(
featdir
)
def
test_loadSettings
():
def
test_loadSettings
():
contents
=
"""
contents
=
"""
...
@@ -498,6 +569,53 @@ def test_getZStatFile():
...
@@ -498,6 +569,53 @@ def test_getZStatFile():
featanalysis
.
getZStatFile
(
featdir
,
zi
)
featanalysis
.
getZStatFile
(
featdir
,
zi
)
def
test_getZStatFile
():
testcases
=
[
([
'
analysis.feat/stats/zstat1.nii.gz
'
,
'
analysis.feat/stats/zstat2.nii.gz
'
],
True
),
([
'
analysis.feat/stats/zstat1.nii.gz
'
],
True
),
([
'
analysis.feat/stats/zstat0.nii.gz
'
],
False
),
([
'
analysis.feat/stats/zstat1.txt
'
],
False
),
]
for
paths
,
shouldPass
in
testcases
:
with
tests
.
testdir
(
paths
)
as
testdir
:
featdir
=
op
.
join
(
testdir
,
'
analysis.feat
'
)
for
zi
in
range
(
len
(
paths
)):
expect
=
op
.
join
(
featdir
,
'
stats
'
,
'
zstat{}.nii.gz
'
.
format
(
zi
+
1
))
if
shouldPass
:
assert
featanalysis
.
getZStatFile
(
featdir
,
zi
)
==
expect
else
:
with
pytest
.
raises
(
fslpath
.
PathError
):
featanalysis
.
getZStatFile
(
featdir
,
zi
)
def
test_getZFStatFile
():
testcases
=
[
([
'
analysis.feat/stats/zfstat1.nii.gz
'
,
'
analysis.feat/stats/zfstat2.nii.gz
'
],
True
),
([
'
analysis.feat/stats/zfstat1.nii.gz
'
],
True
),
([
'
analysis.feat/stats/zfstat0.nii.gz
'
],
False
),
([
'
analysis.feat/stats/zfstat1.txt
'
],
False
),
]
for
paths
,
shouldPass
in
testcases
:
with
tests
.
testdir
(
paths
)
as
testdir
:
featdir
=
op
.
join
(
testdir
,
'
analysis.feat
'
)
for
zi
in
range
(
len
(
paths
)):
expect
=
op
.
join
(
featdir
,
'
stats
'
,
'
zfstat{}.nii.gz
'
.
format
(
zi
+
1
))
if
shouldPass
:
assert
featanalysis
.
getZFStatFile
(
featdir
,
zi
)
==
expect
else
:
with
pytest
.
raises
(
fslpath
.
PathError
):
featanalysis
.
getZFStatFile
(
featdir
,
zi
)
def
test_getClusterMaskFile
():
def
test_getClusterMaskFile
():
testcases
=
[
testcases
=
[
([
'
analysis.feat/cluster_mask_zstat1.nii.gz
'
,
([
'
analysis.feat/cluster_mask_zstat1.nii.gz
'
,
...
...
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