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
7c3ca51d
Commit
7c3ca51d
authored
Aug 10, 2019
by
Paul McCarthy
🚵
Browse files
TEST: Update filetree query tests
parent
d7202e8f
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/test_filetree/test_query.py
View file @
7c3ca51d
...
...
@@ -52,7 +52,7 @@ def _test_data():
yield
def
_expected_matches
(
short_nam
e
,
**
kwargs
):
def
_expected_matches
(
template
,
tre
e
,
**
kwargs
):
matches
=
[]
subjs
=
kwargs
.
get
(
'participant'
,
_subjs
)
...
...
@@ -64,18 +64,20 @@ def _expected_matches(short_name, **kwargs):
sesdir
=
op
.
join
(
'subj-{}'
.
format
(
subj
),
'ses-{}'
.
format
(
ses
))
if
short_nam
e
in
(
'T1w'
,
'T2w'
):
f
=
op
.
join
(
sesdir
,
'{}.nii.gz'
.
format
(
short_nam
e
))
if
templat
e
in
(
'T1w'
,
'T2w'
):
f
=
op
.
join
(
sesdir
,
'{}.nii.gz'
.
format
(
templat
e
))
matches
.
append
(
ftquery
.
Match
(
f
,
short_name
,
template
,
tree
,
{
'participant'
:
subj
,
'session'
:
ses
}))
elif
short_nam
e
==
'surface'
:
elif
templat
e
==
'surface'
:
for
hemi
,
surf
in
it
.
product
(
hemis
,
surfs
):
f
=
op
.
join
(
sesdir
,
'{}.{}.gii'
.
format
(
hemi
,
surf
))
matches
.
append
(
ftquery
.
Match
(
f
,
short_name
,
template
,
tree
,
{
'participant'
:
subj
,
'session'
:
ses
,
'hemi'
:
hemi
,
...
...
@@ -84,19 +86,19 @@ def _expected_matches(short_name, **kwargs):
return
matches
def
_run_and_check_query
(
query
,
short_nam
e
,
asarray
=
False
,
**
vars
):
def
_run_and_check_query
(
query
,
templat
e
,
asarray
=
False
,
**
vars
):
gotmatches
=
query
.
query
(
short_nam
e
,
asarray
=
asarray
,
**
vars
)
expmatches
=
_expected_matches
(
short_nam
e
,
**
{
k
:
[
v
]
for
k
,
v
in
vars
.
items
()})
gotmatches
=
query
.
query
(
templat
e
,
asarray
=
asarray
,
**
vars
)
expmatches
=
_expected_matches
(
template
,
query
.
tre
e
,
**
{
k
:
[
v
]
for
k
,
v
in
vars
.
items
()})
if
not
asarray
:
assert
len
(
gotmatches
)
==
len
(
expmatches
)
for
got
,
exp
in
zip
(
sorted
(
gotmatches
),
sorted
(
expmatches
)):
assert
got
==
exp
else
:
snvars
=
query
.
variables
(
short_nam
e
)
snvars
=
query
.
variables
(
templat
e
)
assert
len
(
snvars
)
==
len
(
gotmatches
.
shape
)
...
...
@@ -108,7 +110,7 @@ def _run_and_check_query(query, short_name, asarray=False, **vars):
for
expmatch
in
expmatches
:
slc
=
[]
for
var
in
query
.
axes
(
short_nam
e
):
for
var
in
query
.
axes
(
templat
e
):
if
var
not
in
vars
or
vars
[
var
]
==
'*'
:
vidx
=
snvars
[
var
].
index
(
expmatch
.
variables
[
var
])
slc
.
append
(
vidx
)
...
...
@@ -128,7 +130,7 @@ def test_query_properties():
'participant'
,
'session'
,
'surf'
]
assert
sorted
(
query
.
short_nam
es
)
==
[
'T1w'
,
'T2w'
,
'surface'
]
assert
sorted
(
query
.
templat
es
)
==
[
'T1w'
,
'T2w'
,
'surface'
]
assert
query
.
variables
(
'T1w'
)
==
{
'participant'
:
[
'01'
,
'02'
,
'03'
],
'session'
:
[
'1'
,
'2'
]}
...
...
@@ -318,7 +320,7 @@ def test_query_subtree():
tree
=
filetree
.
FileTree
.
read
(
'tree1.tree'
,
'.'
)
query
=
filetree
.
FileTreeQuery
(
tree
)
assert
sorted
(
query
.
short_nam
es
)
==
[
'T1w'
,
'surface'
]
assert
sorted
(
query
.
templat
es
)
==
[
'T1w'
,
'
surfdir/
surface'
]
qvars
=
query
.
variables
()
assert
sorted
(
qvars
.
keys
())
==
[
'hemi'
,
'participant'
,
'surf'
]
...
...
@@ -330,7 +332,7 @@ def test_query_subtree():
assert
sorted
(
qvars
.
keys
())
==
[
'participant'
]
assert
qvars
[
'participant'
]
==
[
'01'
,
'02'
,
'03'
]
qvars
=
query
.
variables
(
'surface'
)
qvars
=
query
.
variables
(
'
surfdir/
surface'
)
assert
sorted
(
qvars
.
keys
())
==
[
'hemi'
,
'participant'
,
'surf'
]
assert
qvars
[
'hemi'
]
==
[
'L'
,
'R'
]
assert
qvars
[
'participant'
]
==
[
'01'
,
'02'
,
'03'
]
...
...
@@ -346,7 +348,7 @@ def test_query_subtree():
assert
[
m
.
filename
for
m
in
sorted
(
got
)]
==
[
op
.
join
(
'subj-01'
,
'T1w.nii.gz'
)]
got
=
query
.
query
(
'surface'
)
got
=
query
.
query
(
'
surfdir/
surface'
)
assert
[
m
.
filename
for
m
in
sorted
(
got
)]
==
[
op
.
join
(
'subj-01'
,
'surf'
,
'L.pial.gii'
),
op
.
join
(
'subj-01'
,
'surf'
,
'L.white.gii'
),
...
...
@@ -361,7 +363,7 @@ def test_query_subtree():
op
.
join
(
'subj-03'
,
'surf'
,
'R.pial.gii'
),
op
.
join
(
'subj-03'
,
'surf'
,
'R.white.gii'
)]
got
=
query
.
query
(
'surface'
,
hemi
=
'L'
)
got
=
query
.
query
(
'
surfdir/
surface'
,
hemi
=
'L'
)
assert
[
m
.
filename
for
m
in
sorted
(
got
)]
==
[
op
.
join
(
'subj-01'
,
'surf'
,
'L.pial.gii'
),
op
.
join
(
'subj-01'
,
'surf'
,
'L.white.gii'
),
...
...
@@ -370,7 +372,7 @@ def test_query_subtree():
op
.
join
(
'subj-03'
,
'surf'
,
'L.pial.gii'
),
op
.
join
(
'subj-03'
,
'surf'
,
'L.white.gii'
)]
got
=
query
.
query
(
'surface'
,
surf
=
'white'
)
got
=
query
.
query
(
'
surfdir/
surface'
,
surf
=
'white'
)
assert
[
m
.
filename
for
m
in
sorted
(
got
)]
==
[
op
.
join
(
'subj-01'
,
'surf'
,
'L.white.gii'
),
op
.
join
(
'subj-01'
,
'surf'
,
'R.white.gii'
),
...
...
@@ -394,16 +396,17 @@ def test_scan():
t1wf
=
op
.
join
(
sesdir
,
'T1w.nii.gz'
)
t2wf
=
op
.
join
(
sesdir
,
'T2w.nii.gz'
)
expmatches
.
append
(
ftquery
.
Match
(
t1wf
,
'T1w'
,
{
'participant'
:
subj
,
'session'
:
ses
}))
expmatches
.
append
(
ftquery
.
Match
(
t2wf
,
'T2w'
,
{
'participant'
:
subj
,
'session'
:
ses
}))
expmatches
.
append
(
ftquery
.
Match
(
t1wf
,
'T1w'
,
tree
,
{
'participant'
:
subj
,
'session'
:
ses
}))
expmatches
.
append
(
ftquery
.
Match
(
t2wf
,
'T2w'
,
tree
,
{
'participant'
:
subj
,
'session'
:
ses
}))
for
hemi
,
surf
in
it
.
product
(
_hemis
,
_surfs
):
surff
=
op
.
join
(
sesdir
,
'{}.{}.gii'
.
format
(
hemi
,
surf
))
expmatches
.
append
(
ftquery
.
Match
(
surff
,
'surface'
,
tree
,
{
'participant'
:
subj
,
'session'
:
ses
,
'surf'
:
surf
,
...
...
@@ -414,7 +417,7 @@ def test_scan():
for
got
,
exp
in
zip
(
sorted
(
gotmatches
),
sorted
(
expmatches
)):
assert
got
.
filename
==
exp
.
filename
assert
got
.
short_name
==
exp
.
short_nam
e
assert
got
.
template
==
exp
.
templat
e
assert
got
.
variables
==
exp
.
variables
...
...
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