self, name)
assert name.startswith('-'), msg
- self.default = default or (None if self.arity else False)
+ self.default = default if (default or self.arity) else False
@property
def value(self):
:param keyvalue_pairs: (str) ['key1=val1', 'key2=val2', ...]
"""
self._value = {}
- for pair in keyvalue_pairs:
- key, sep, val = pair.partition('=')
- if not sep:
- raiseCLIError(
- CLISyntaxError('Argument syntax error '),
- details='%s is missing a "=" (usage: key1=val1 )\n' % pair)
+ try:
+ for pair in keyvalue_pairs:
+ key, sep, val = pair.partition('=')
+ assert sep, ' %s misses a "=" (usage: key1=val1 )\n' % (pair)
self._value[key] = val
+ except Exception as e:
+ raiseCLIError(e, 'KeyValueArgument Syntax Error')
class ProgressBarArgument(FlagArgument):
isinstance(parsed_name, list)) else [parsed_name, ]
self.assertEqual(exp_name, a.parsed_name)
- exp_default = default or (None if arity else False)
+ exp_default = default if (default or arity) else False
self.assertEqual(exp_default, a.default)
def test_value(self):
def test_value(self):
kva = argument.KeyValueArgument(parsed_name='--keyval')
- self.assertEqual(kva.value, None)
+ self.assertEqual(kva.value, {})
for kvpairs in (
'strval', 'key=val', 2.8, 42, None,
('key', 'val'), ('key val'), ['=val', 'key=val'],
['key1=val1', 'key2 val2'], ('key1 = val1', )):
- self.assertRaises(errors.CLIError, kva.value, kvpairs)
+ try:
+ kva.value = kvpairs
+ except Exception as e:
+ self.assertTrue(isinstance(e, errors.CLIError))
for kvpairs, exp in (
(('key=val', ), {'key': 'val'}),
(['key1=val1', 'key2=val2'], {'key1': 'val1', 'key2': 'val2'}),