File diff 6c89febb9059 → 95f7524b000e
tests/test_cliutil.py
Show inline comments
...
 
@@ -298,3 +298,36 @@ def test_enum_arg_choices_str_defaults(arg_enum):
 
def test_enum_arg_choices_str_args(arg_enum):
 
    sep = '/'
 
    assert arg_enum.choices_str(sep, '{}') == sep.join(c.value for c in ArgChoices)
 

	
 
@pytest.mark.parametrize('values,sep', testutil.combine_values(
 
    [['foo'], ['bar', 'baz'], ['qu', 'quu', 'quux']],
 
    [',', ', ', '  ,', ' ,  '],
 
))
 
def test_extend_action_once(values, sep):
 
    action = cliutil.ExtendAction(['-t'], 'result')
 
    args = argparse.Namespace()
 
    action(None, args, sep.join(values), '-t')
 
    assert args.result == values
 

	
 
def test_extend_action_multi():
 
    action = cliutil.ExtendAction(['-t'], 'result')
 
    args = argparse.Namespace()
 
    action(None, args, 'foo,bar', '-t')
 
    action(None, args, 'baz, quux', '-t')
 
    assert args.result == ['foo', 'bar', 'baz', 'quux']
 

	
 
def test_extend_action_from_default():
 
    action = cliutil.ExtendAction(['-t'], 'result')
 
    args = argparse.Namespace(result=['foo'])
 
    action(None, args, 'bar , baz', '-t')
 
    assert args.result == ['foo', 'bar', 'baz']
 

	
 
@pytest.mark.parametrize('pattern,expected', [
 
    (',', ['foo', ' bar']),
 
    (r'\s+', ['foo,', 'bar']),
 
])
 
def test_extend_action_custom_pattern(pattern, expected):
 
    action = cliutil.ExtendAction(['-t'], 'result', const=pattern)
 
    args = argparse.Namespace()
 
    action(None, args, 'foo, bar', '-t')
 
    assert args.result == expected