Merge "Make List option format bounds-sensitive"
This commit is contained in:
commit
84655714b6
|
@ -151,6 +151,10 @@ class GeneratorTestCase(base.BaseTestCase):
|
||||||
'list_opt': cfg.ListOpt('list_opt',
|
'list_opt': cfg.ListOpt('list_opt',
|
||||||
default=['1', '2', '3'],
|
default=['1', '2', '3'],
|
||||||
help='a list'),
|
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',
|
'list_opt_single': cfg.ListOpt('list_opt_single',
|
||||||
default='1',
|
default='1',
|
||||||
help='a list'),
|
help='a list'),
|
||||||
|
@ -630,6 +634,17 @@ class GeneratorTestCase(base.BaseTestCase):
|
||||||
|
|
||||||
# a list (list value)
|
# a list (list value)
|
||||||
#list_opt = 1,2,3
|
#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',
|
('list_opt_single',
|
||||||
dict(opts=[('test', [(None, [opts['list_opt_single']])])],
|
dict(opts=[('test', [(None, [opts['list_opt_single']])])],
|
||||||
|
|
|
@ -525,14 +525,15 @@ class List(ConfigType):
|
||||||
)
|
)
|
||||||
|
|
||||||
def _formatter(self, value):
|
def _formatter(self, value):
|
||||||
|
fmtstr = '[{}]' if self.bounds else '{}'
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, six.string_types):
|
||||||
return value
|
return fmtstr.format(value)
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
value = [
|
value = [
|
||||||
six.text_type(v)
|
six.text_type(v)
|
||||||
for v in value
|
for v in value
|
||||||
]
|
]
|
||||||
return ','.join(value)
|
return fmtstr.format(','.join(value))
|
||||||
|
|
||||||
|
|
||||||
class Range(ConfigType):
|
class Range(ConfigType):
|
||||||
|
|
Loading…
Reference in New Issue