Commit 7f44ac2e authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

TEST: test single-char args in fast wrapper

parent aa1fef99
......@@ -27,6 +27,10 @@ def checkResult(cmd, base, args, stripdir=None):
Pre python 3.7, we couldn't control the order in which command
line args were generated, so we needed to test all possible orderings.
But for Python >= 3.7, the order in which kwargs are passed will
be the same as the order in which they are rendered, so this function
is not required.
:arg cmd: Generated command
:arg base: Beginning of expected command
:arg args: Sequence of expected arguments
......@@ -366,6 +370,12 @@ def test_fast():
expected = [cmd, '--out=myseg', '--class=3', '--verbose', 'in1', 'in2', 'in3']
assert result.stdout[0] == ' '.join(expected)
result = fw.fast(('in1', 'in2', 'in3'), 'myseg', n_classes=3,
a='reg.mat', A=('csf', 'gm', 'wm'), Prior=True)
expected = [cmd, '--out=myseg', '--class=3', '-a', 'reg.mat',
'-A', 'csf', 'gm', 'wm', '--Prior', 'in1', 'in2', 'in3']
assert result.stdout[0] == ' '.join(expected)
def test_fsl_anat():
with asrt.disabled(), \
......
......@@ -30,11 +30,24 @@ from .. import mockFSLDIR, cleardir, checkdir, testdir, touch
from ..test_run import mock_fsl_sub
def test_applyArgStyle_default():
kwargs = {
'arg1' : 'val',
'arg2' : ['val1', 'val2'],
'a' : 'val',
'b' : ['val1', 'val2'],
}
exp = ['--arg1=val', '--arg2=val1,val2', '-a', 'val', '-b', 'val1', 'val2']
assert wutils.applyArgStyle(**kwargs) == exp
def test_applyArgStyle():
kwargs = {
'name' : 'val',
'name2' : ['val1', 'val2'],
'name3' : 'val1 val2',
}
# these combinations of style+valsep should
......@@ -51,28 +64,70 @@ def test_applyArgStyle():
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', '-name3', 'val1 val2']),
('-', '"', ['-name', 'val', '-name2', 'val1 val2', '-name3', 'val1 val2']),
('-', ',', ['-name', 'val', '-name2', 'val1,val2', '-name3', 'val1 val2']),
('--', ' ', ['--name val', '--name2 val1 val2']),
('--', '"', ['--name val', '--name2 "val1 val2"']),
('--', ',', ['--name val', '--name2 val1,val2']),
('--', ' ', ['--name', 'val', '--name2', 'val1', 'val2', '--name3', 'val1 val2']),
('--', '"', ['--name', 'val', '--name2', 'val1 val2', '--name3', 'val1 val2']),
('--', ',', ['--name', 'val', '--name2', 'val1,val2', '--name3', 'val1 val2']),
('-=', '"', [' -name=val', '-name2="val1 val2"']),
('-=', ',', [' -name=val', '-name2=val1,val2']),
('-=', '"', ['-name=val', '-name2=val1 val2', '-name3=val1 val2']),
('-=', ',', ['-name=val', '-name2=val1,val2', '-name3=val1 val2']),
('--=', '"', ['--name=val', '--name2="val1 val2"']),
('--=', ',', ['--name=val', '--name2=val1,val2']),
('--=', '"', ['--name=val', '--name2=val1 val2', '--name3=val1 val2']),
('--=', ',', ['--name=val', '--name2=val1,val2', '--name3=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 == exp
def test_applyArgStyle_charstyle():
kwargs = {
'n' : 'val',
'm' : ['val1', 'val2'],
'o' : 'val1 val2',
}
# these combinations of charstyle+
# charsep should raise an error
with pytest.raises(ValueError):
wutils.applyArgStyle(charstyle='--=', charsep=' ', **kwargs)
with pytest.raises(ValueError):
wutils.applyArgStyle(charstyle='-=', charsep=' ', **kwargs)
# unsupported chrastyle/charsep
with pytest.raises(ValueError):
wutils.applyArgStyle(charstyle='?', **kwargs)
with pytest.raises(ValueError):
wutils.applyArgStyle('-', charsep='b', **kwargs)
# style, valsep, charstyle, charsep, expected_result.
# Order of arguments is not guaranteed
tests = [
('-', ' ', ['-n', 'val', '-m', 'val1', 'val2', '-o', 'val1 val2']),
('-', '"', ['-n', 'val', '-m', 'val1 val2', '-o', 'val1 val2']),
('-', ',', ['-n', 'val', '-m', 'val1,val2', '-o', 'val1 val2']),
('--', ' ', ['--n', 'val', '--m', 'val1','val2', '--o', 'val1 val2']),
('--', '"', ['--n', 'val', '--m', 'val1 val2', '--o', 'val1 val2']),
('--', ',', ['--n', 'val', '--m', 'val1,val2', '--o', 'val1 val2']),
('-=', '"', ['-n=val', '-m=val1 val2', '-o=val1 val2']),
('-=', ',', ['-n=val', '-m=val1,val2', '-o=val1 val2']),
('--=', '"', ['--n=val', '--m=val1 val2', '--o=val1 val2']),
('--=', ',', ['--n=val', '--m=val1,val2', '--o=val1 val2']),
]
for style, valsep, exp in tests:
result = wutils.applyArgStyle(charstyle=style, charsep=valsep, **kwargs)
assert result in (exp[0] + exp[1], exp[1] + exp[0])
assert result == exp
def test_applyArgStyle_argmap():
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment