Merge "Make List option format bounds-sensitive"

This commit is contained in:
Zuul 2018-04-16 03:04:09 +00:00 committed by Gerrit Code Review
commit 84655714b6
2 changed files with 18 additions and 2 deletions

View File

@ -151,6 +151,10 @@ class GeneratorTestCase(base.BaseTestCase):
'list_opt': cfg.ListOpt('list_opt',
default=['1', '2', '3'],
help='a list'),
'list_opt_with_bounds': cfg.ListOpt('list_opt_with_bounds',
default=['1', '2', '3'],
help='a list',
bounds=True),
'list_opt_single': cfg.ListOpt('list_opt_single',
default='1',
help='a list'),
@ -630,6 +634,17 @@ class GeneratorTestCase(base.BaseTestCase):
# a list (list value)
#list_opt = 1,2,3
''')),
('list_opt_with_bounds',
dict(opts=[('test', [(None, [opts['list_opt_with_bounds']])])],
expected='''[DEFAULT]
#
# From test
#
# a list (list value)
#list_opt_with_bounds = [1,2,3]
''')),
('list_opt_single',
dict(opts=[('test', [(None, [opts['list_opt_single']])])],

View File

@ -525,14 +525,15 @@ class List(ConfigType):
)
def _formatter(self, value):
fmtstr = '[{}]' if self.bounds else '{}'
if isinstance(value, six.string_types):
return value
return fmtstr.format(value)
if isinstance(value, list):
value = [
six.text_type(v)
for v in value
]
return ','.join(value)
return fmtstr.format(','.join(value))
class Range(ConfigType):