Commit f52b39db authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Allow non-None empty default values in Args

Refs: #4058
parent 631b7c35
......@@ -67,7 +67,7 @@ class Argument(object):
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
def value(self):
......@@ -296,13 +296,13 @@ class KeyValueArgument(Argument):
:param keyvalue_pairs: (str) ['key1=val1', 'key2=val2', ...]
self._value = {}
for pair in keyvalue_pairs:
key, sep, val = pair.partition('=')
if not sep:
CLISyntaxError('Argument syntax error '),
details='%s is missing a "=" (usage: key1=val1 )\n' % pair)
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):
......@@ -75,7 +75,7 @@ class Argument(TestCase):
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):
......@@ -301,12 +301,15 @@ class KeyValueArgument(TestCase):
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)
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'}),
Markdown is supported
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