diff options
author | Zuul <zuul@review.openstack.org> | 2018-04-16 03:04:09 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2018-04-16 03:04:09 +0000 |
commit | 84655714b656c8296bfd70aeb5daf5996e1f5add (patch) | |
tree | d1522021c73a2a826e0adf3eb031151ae58cc88c | |
parent | 8f97bdb646cd8a581bd6862fa0453458ba96f5c6 (diff) | |
parent | a69701c495947a2bbe618e71e20d6203977a6943 (diff) | |
download | oslo-config-84655714b656c8296bfd70aeb5daf5996e1f5add.tar.gz |
Merge "Make List option format bounds-sensitive"6.1.0
-rw-r--r-- | oslo_config/tests/test_generator.py | 15 | ||||
-rw-r--r-- | oslo_config/types.py | 5 |
2 files changed, 18 insertions, 2 deletions
diff --git a/oslo_config/tests/test_generator.py b/oslo_config/tests/test_generator.py index e01bbab..8575d8e 100644 --- a/oslo_config/tests/test_generator.py +++ b/oslo_config/tests/test_generator.py @@ -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'), @@ -631,6 +635,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']])])], expected='''[DEFAULT] diff --git a/oslo_config/types.py b/oslo_config/types.py index 752fe1a..06a81dd 100644 --- a/oslo_config/types.py +++ b/oslo_config/types.py @@ -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): |