diff options
-rw-r--r-- | oslo_config/tests/test_generator.py | 15 | ||||
-rw-r--r-- | oslo_config/types.py | 4 |
2 files changed, 19 insertions, 0 deletions
diff --git a/oslo_config/tests/test_generator.py b/oslo_config/tests/test_generator.py index f2875ea..1f64ebe 100644 --- a/oslo_config/tests/test_generator.py +++ b/oslo_config/tests/test_generator.py @@ -137,6 +137,9 @@ class GeneratorTestCase(base.BaseTestCase): default=['1', '2', '3'], sample_default=['5', '6'], help='multiple strings'), + 'string_type_with_bad_default': cfg.Opt('string_type_with_bad_default', + help='string with bad default', + default=4096), 'custom_type': cfg.Opt('custom_type', help='custom help', type=type('string')), @@ -619,6 +622,18 @@ class GeneratorTestCase(base.BaseTestCase): # custom help (unknown value) #custom_type = <None> ''')), + ('string_type_with_bad_default', + dict(opts=[('test', [(None, + [opts['string_type_with_bad_default']])])], + expected='''[DEFAULT] + +# +# From test +# + +# string with bad default (string value) +#string_type_with_bad_default = 4096 +''')), ] output_file_scenarios = [ diff --git a/oslo_config/types.py b/oslo_config/types.py index c098bfa..a126681 100644 --- a/oslo_config/types.py +++ b/oslo_config/types.py @@ -21,6 +21,7 @@ Use these classes as values for the `type` argument to """ import operator import re +import warnings import abc import netaddr @@ -46,6 +47,9 @@ class ConfigType(object): return [default_str] def quote_trailing_and_leading_space(self, str_val): + if not isinstance(str_val, six.string_types): + warnings.warn('converting \'%s\' to a string' % str_val) + str_val = six.text_type(str_val) if str_val.strip() != str_val: return '"%s"' % str_val return str_val |