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
23a40096
Commit
23a40096
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Test FileTreeQuery with scalar files
parent
60614f25
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
tests/test_filetree/test_query.py
+41
-21
41 additions, 21 deletions
tests/test_filetree/test_query.py
with
41 additions
and
21 deletions
tests/test_filetree/test_query.py
+
41
−
21
View file @
23a40096
...
...
@@ -25,6 +25,7 @@ subj-{participant}
T1w.nii.gz (T1w)
T2w.nii.gz (T2w)
{hemi}.{surf}.gii (surface)
scalar_file.txt (scalar)
"""
.
strip
()
_subjs
=
[
'
01
'
,
'
02
'
,
'
03
'
]
...
...
@@ -36,7 +37,7 @@ _surfs = ['midthickness', 'pial', 'white']
@contextlib.contextmanager
def
_test_data
():
files
=
[]
files
=
[
'
scalar_file.txt
'
]
for
subj
,
ses
in
it
.
product
(
_subjs
,
_sess
):
sesdir
=
op
.
join
(
'
subj-{}
'
.
format
(
subj
),
'
ses-{}
'
.
format
(
ses
))
...
...
@@ -60,6 +61,12 @@ def _expected_matches(template, tree, **kwargs):
surfs
=
kwargs
.
get
(
'
surf
'
,
_surfs
)
hemis
=
kwargs
.
get
(
'
hemi
'
,
_hemis
)
if
template
==
'
scalar
'
:
matches
.
append
(
ftquery
.
Match
(
'
scalar_file.txt
'
,
template
,
tree
,
{}))
for
subj
,
ses
in
it
.
product
(
subjs
,
sess
):
sesdir
=
op
.
join
(
'
subj-{}
'
.
format
(
subj
),
'
ses-{}
'
.
format
(
ses
))
...
...
@@ -100,7 +107,10 @@ def _run_and_check_query(query, template, asarray=False, **vars):
else
:
snvars
=
query
.
variables
(
template
)
assert
len
(
snvars
)
==
len
(
gotmatches
.
shape
)
if
len
(
snvars
)
==
0
:
assert
gotmatches
.
shape
==
(
1
,)
else
:
assert
len
(
snvars
)
==
len
(
gotmatches
.
shape
)
for
i
,
var
in
enumerate
(
sorted
(
snvars
.
keys
())):
if
var
not
in
vars
or
vars
[
var
]
==
'
*
'
:
...
...
@@ -124,30 +134,32 @@ def test_query_properties():
tree
=
filetree
.
FileTree
.
read
(
'
_test_tree.tree
'
,
'
.
'
)
query
=
filetree
.
FileTreeQuery
(
tree
)
assert
sorted
(
query
.
axes
(
'
scalar
'
))
==
[]
assert
sorted
(
query
.
axes
(
'
T1w
'
))
==
[
'
participant
'
,
'
session
'
]
assert
sorted
(
query
.
axes
(
'
T2w
'
))
==
[
'
participant
'
,
'
session
'
]
assert
sorted
(
query
.
axes
(
'
surface
'
))
==
[
'
hemi
'
,
'
participant
'
,
'
session
'
,
'
surf
'
]
assert
sorted
(
query
.
templates
)
==
[
'
T1w
'
,
'
T2w
'
,
'
surface
'
]
assert
query
.
variables
(
'
T1w
'
)
==
{
'
participant
'
:
[
'
01
'
,
'
02
'
,
'
03
'
],
'
session
'
:
[
'
1
'
,
'
2
'
]}
assert
query
.
variables
(
'
T2w
'
)
==
{
'
participant
'
:
[
'
01
'
,
'
02
'
,
'
03
'
],
'
session
'
:
[
'
1
'
,
'
2
'
]}
assert
query
.
variables
(
'
surface
'
)
==
{
'
participant
'
:
[
'
01
'
,
'
02
'
,
'
03
'
],
'
session
'
:
[
'
1
'
,
'
2
'
],
'
surf
'
:
[
'
midthickness
'
,
'
pial
'
,
'
white
'
],
'
hemi
'
:
[
'
L
'
,
'
R
'
]}
assert
query
.
variables
()
==
{
'
participant
'
:
[
'
01
'
,
'
02
'
,
'
03
'
],
'
session
'
:
[
'
1
'
,
'
2
'
],
'
surf
'
:
[
'
midthickness
'
,
'
pial
'
,
'
white
'
],
'
hemi
'
:
[
'
L
'
,
'
R
'
]}
assert
sorted
(
query
.
templates
)
==
[
'
T1w
'
,
'
T2w
'
,
'
scalar
'
,
'
surface
'
]
assert
query
.
variables
(
'
scalar
'
)
==
{}
assert
query
.
variables
(
'
T1w
'
)
==
{
'
participant
'
:
[
'
01
'
,
'
02
'
,
'
03
'
],
'
session
'
:
[
'
1
'
,
'
2
'
]}
assert
query
.
variables
(
'
T2w
'
)
==
{
'
participant
'
:
[
'
01
'
,
'
02
'
,
'
03
'
],
'
session
'
:
[
'
1
'
,
'
2
'
]}
assert
query
.
variables
(
'
surface
'
)
==
{
'
participant
'
:
[
'
01
'
,
'
02
'
,
'
03
'
],
'
session
'
:
[
'
1
'
,
'
2
'
],
'
surf
'
:
[
'
midthickness
'
,
'
pial
'
,
'
white
'
],
'
hemi
'
:
[
'
L
'
,
'
R
'
]}
assert
query
.
variables
()
==
{
'
participant
'
:
[
'
01
'
,
'
02
'
,
'
03
'
],
'
session
'
:
[
'
1
'
,
'
2
'
],
'
surf
'
:
[
'
midthickness
'
,
'
pial
'
,
'
white
'
],
'
hemi
'
:
[
'
L
'
,
'
R
'
]}
def
test_query
():
...
...
@@ -155,6 +167,7 @@ def test_query():
tree
=
filetree
.
FileTree
.
read
(
'
_test_tree.tree
'
,
'
.
'
)
query
=
filetree
.
FileTreeQuery
(
tree
)
_run_and_check_query
(
query
,
'
scalar
'
)
_run_and_check_query
(
query
,
'
T1w
'
)
_run_and_check_query
(
query
,
'
T1w
'
,
participant
=
'
01
'
)
_run_and_check_query
(
query
,
'
T1w
'
,
session
=
'
2
'
)
...
...
@@ -269,6 +282,7 @@ def test_query_asarray():
tree
=
filetree
.
FileTree
.
read
(
'
_test_tree.tree
'
,
'
.
'
)
query
=
filetree
.
FileTreeQuery
(
tree
)
_run_and_check_query
(
query
,
'
scalar
'
,
asarray
=
True
)
_run_and_check_query
(
query
,
'
T1w
'
,
asarray
=
True
)
_run_and_check_query
(
query
,
'
T1w
'
,
asarray
=
True
,
participant
=
'
01
'
)
_run_and_check_query
(
query
,
'
T1w
'
,
asarray
=
True
,
session
=
'
2
'
)
...
...
@@ -388,7 +402,10 @@ def test_scan():
tree
=
filetree
.
FileTree
.
read
(
'
_test_tree.tree
'
,
'
.
'
)
gotmatches
=
ftquery
.
scan
(
tree
)
expmatches
=
[]
expmatches
=
[
ftquery
.
Match
(
'
scalar_file.txt
'
,
'
scalar
'
,
tree
,
{})]
for
subj
,
ses
in
it
.
product
(
_subjs
,
_sess
):
...
...
@@ -416,6 +433,8 @@ def test_scan():
assert
len
(
gotmatches
)
==
len
(
expmatches
)
for
got
,
exp
in
zip
(
sorted
(
gotmatches
),
sorted
(
expmatches
)):
assert
got
==
exp
assert
str
(
got
)
==
str
(
exp
)
assert
got
.
filename
==
exp
.
filename
assert
got
.
template
==
exp
.
template
assert
got
.
variables
==
exp
.
variables
...
...
@@ -433,6 +452,7 @@ def test_allVariables():
'
surf
'
:
_surfs
,
'
hemi
'
:
_hemis
}
expsnames
=
{
'
scalar
'
:
[],
'
T1w
'
:
[
'
participant
'
,
'
session
'
],
'
T2w
'
:
[
'
participant
'
,
'
session
'
],
'
surface
'
:
[
'
hemi
'
,
'
participant
'
,
'
session
'
,
'
surf
'
]}
...
...
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