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
7e9c7447
Commit
7e9c7447
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
unit tests for applyArgStyle function
parent
d7169a6b
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_wrapperutils.py
+141
-0
141 additions, 0 deletions
tests/test_wrapperutils.py
with
141 additions
and
0 deletions
tests/test_wrapperutils.py
0 → 100644
+
141
−
0
View file @
7e9c7447
#!/usr/bin/env python
#
# test_wrapperutils.py -
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import
shlex
import
collections
import
pytest
import
fsl.wrappers.wrapperutils
as
wutils
def
test_applyArgStyle
():
"""
"""
kwargs
=
{
'
name
'
:
'
val
'
,
'
name2
'
:
[
'
val1
'
,
'
val2
'
],
}
# these combinations of style+valsep should
# raise an error
with
pytest
.
raises
(
ValueError
):
wutils
.
applyArgStyle
(
style
=
'
-=
'
,
valsep
=
'
'
,
**
kwargs
)
with
pytest
.
raises
(
ValueError
):
wutils
.
applyArgStyle
(
style
=
'
--=
'
,
valsep
=
'
'
,
**
kwargs
)
# unsupported style/valsep
with
pytest
.
raises
(
ValueError
):
wutils
.
applyArgStyle
(
'
?
'
,
**
kwargs
)
with
pytest
.
raises
(
ValueError
):
wutils
.
applyArgStyle
(
'
-
'
,
valsep
=
'
b
'
,
**
kwargs
)
# style, valsep, expected_result.
# Order of arguments is not guaranteed
tests
=
[
(
'
-
'
,
'
'
,
[
'
-name val
'
,
'
-name2 val1 val2
'
]),
(
'
-
'
,
'"'
,
[
'
-name val
'
,
'
-name2
"
val1 val2
"'
]),
(
'
-
'
,
'
,
'
,
[
'
-name val
'
,
'
-name2 val1,val2
'
]),
(
'
--
'
,
'
'
,
[
'
--name val
'
,
'
--name2 val1 val2
'
]),
(
'
--
'
,
'"'
,
[
'
--name val
'
,
'
--name2
"
val1 val2
"'
]),
(
'
--
'
,
'
,
'
,
[
'
--name val
'
,
'
--name2 val1,val2
'
]),
(
'
-=
'
,
'"'
,
[
'
-name=val
'
,
'
-name2=
"
val1 val2
"'
]),
(
'
-=
'
,
'
,
'
,
[
'
-name=val
'
,
'
-name2=val1,val2
'
]),
(
'
--=
'
,
'"'
,
[
'
--name=val
'
,
'
--name2=
"
val1 val2
"'
]),
(
'
--=
'
,
'
,
'
,
[
'
--name=val
'
,
'
--name2=val1,val2
'
]),
]
for
style
,
valsep
,
exp
in
tests
:
exp
=
[
shlex
.
split
(
e
)
for
e
in
exp
]
result
=
wutils
.
applyArgStyle
(
style
,
valsep
=
valsep
,
**
kwargs
)
assert
result
in
(
exp
[
0
]
+
exp
[
1
],
exp
[
1
]
+
exp
[
0
])
def
test_applyArgStyle_argmap
():
kwargs
=
{
'
name1
'
:
'
val1
'
,
'
name2
'
:
'
val2
'
,
}
argmap
=
{
'
name1
'
:
'
n
'
,
'
name2
'
:
'
m
'
,
}
# order not guaranteed
exp
=
[
shlex
.
split
(
'
-n val1 -m val2
'
),
shlex
.
split
(
'
-m val2 -n val1
'
)]
assert
wutils
.
applyArgStyle
(
'
-
'
,
argmap
=
argmap
,
**
kwargs
)
in
exp
def
test_applyArgStyle_valmap
():
valmap
=
{
'
a
'
:
wutils
.
SHOW_IF_TRUE
,
'
b
'
:
wutils
.
HIDE_IF_TRUE
,
}
# kwargs, expected
tests
=
[
({
},
[
''
]),
({
'
a
'
:
False
,
},
[
''
]),
({
'
a
'
:
True
,
},
[
'
-a
'
]),
({
'
b
'
:
False
},
[
'
-b
'
]),
({
'
b
'
:
True
},
[
''
]),
({
'
a
'
:
False
,
'
b
'
:
True
},
[
''
]),
({
'
a
'
:
True
,
'
b
'
:
True
},
[
'
-a
'
]),
({
'
a
'
:
False
,
'
b
'
:
False
},
[
'
-b
'
]),
({
'
a
'
:
False
,
'
b
'
:
True
},
[
''
]),
({
'
a
'
:
True
,
'
b
'
:
False
},
[
'
-a -b
'
,
'
-b -a
'
]),
({
'
a
'
:
True
,
'
b
'
:
True
},
[
'
-a
'
]),
]
for
kwargs
,
expected
in
tests
:
expected
=
[
shlex
.
split
(
e
)
for
e
in
expected
]
assert
wutils
.
applyArgStyle
(
'
-
'
,
valmap
=
valmap
,
**
kwargs
)
in
expected
def
test_applyArgStyle_argmap_valmap
():
argmap
=
{
'
a1
'
:
'
a
'
,
'
a2
'
:
'
b
'
}
valmap
=
{
'
a
'
:
wutils
.
SHOW_IF_TRUE
,
'
b
'
:
wutils
.
HIDE_IF_TRUE
,
}
# kwargs, expected
tests
=
[
({
},
[
''
]),
({
'
a1
'
:
False
,
},
[
''
]),
({
'
a1
'
:
True
,
},
[
'
-a
'
]),
({
'
a2
'
:
False
},
[
'
-b
'
]),
({
'
a2
'
:
True
},
[
''
]),
({
'
a1
'
:
False
,
'
a2
'
:
True
},
[
''
]),
({
'
a1
'
:
True
,
'
a2
'
:
True
},
[
'
-a
'
]),
({
'
a1
'
:
False
,
'
a2
'
:
False
},
[
'
-b
'
]),
({
'
a1
'
:
False
,
'
a2
'
:
True
},
[
''
]),
({
'
a1
'
:
True
,
'
a2
'
:
False
},
[
'
-a -b
'
,
'
-b -a
'
]),
({
'
a1
'
:
True
,
'
a2
'
:
True
},
[
'
-a
'
]),
]
for
kwargs
,
expected
in
tests
:
expected
=
[
shlex
.
split
(
e
)
for
e
in
expected
]
assert
wutils
.
applyArgStyle
(
'
-
'
,
argmap
=
argmap
,
valmap
=
valmap
,
**
kwargs
)
in
expected
# TODO
# - test _FileOrImage LOAD tuple order
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