Skip to content
Snippets Groups Projects
Commit 7e9c7447 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

unit tests for applyArgStyle function

parent d7169a6b
No related branches found
No related tags found
No related merge requests found
#!/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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment