diff options
author | Chaozhe.Chen <chaozhe.chen@easystack.cn> | 2016-02-16 15:56:34 +0800 |
---|---|---|
committer | Chaozhe.Chen <chaozhe.chen@easystack.cn> | 2016-02-16 16:48:56 +0800 |
commit | 3dfd4a4e657426534b132cbe0c2dbed554d060f2 (patch) | |
tree | ca2844fa5cd7834eaa506e9455ff850efb470606 | |
parent | 1482e5c601d0f75a13972cc808c5fc5a98513624 (diff) | |
download | oslo-config-3dfd4a4e657426534b132cbe0c2dbed554d060f2.tar.gz |
Fix wrong check with non-None value when format group
This patch is same to the bug-fix 'Fix can't generate config sample
with non-None value'[1].
There is pitfall in statement like:
if getattr(opt.type, 'min', None)
The check returns False When opt.type.min equals 0,
We should check this with None.
This patch will fix it and add unit tests for the change.
[1]https://review.openstack.org/#/c/267566/2
Change-Id: Iec6d8d70c67f641ae53976bde13697ce0f4982c1
-rw-r--r-- | oslo_config/sphinxext.py | 4 | ||||
-rw-r--r-- | oslo_config/tests/test_sphinxext.py | 44 |
2 files changed, 46 insertions, 2 deletions
diff --git a/oslo_config/sphinxext.py b/oslo_config/sphinxext.py index 3312866..7f3ca18 100644 --- a/oslo_config/sphinxext.py +++ b/oslo_config/sphinxext.py @@ -108,9 +108,9 @@ def _format_group(app, namespace, group_name, group_obj, opt_list): if default: default = '``' + default + '``' yield _indent(':Default: %s' % default) - if getattr(opt.type, 'min', None): + if getattr(opt.type, 'min', None) is not None: yield _indent(':Minimum Value: %s' % opt.type.min) - if getattr(opt.type, 'max', None): + if getattr(opt.type, 'max', None) is not None: yield _indent(':Maximum Value: %s' % opt.type.max) if getattr(opt.type, 'choices', None): choices_text = ', '.join([_get_choice_text(choice) diff --git a/oslo_config/tests/test_sphinxext.py b/oslo_config/tests/test_sphinxext.py index d584943..0ad56c4 100644 --- a/oslo_config/tests/test_sphinxext.py +++ b/oslo_config/tests/test_sphinxext.py @@ -91,6 +91,28 @@ class FormatGroupTest(base.BaseTestCase): ''').lstrip(), results) + def test_with_min_0(self): + results = '\n'.join(list(sphinxext._format_group( + app=mock.Mock(), + namespace=None, + group_name=None, + group_obj=None, + opt_list=[ + cfg.IntOpt('opt_name', + min=0), + ], + ))) + self.assertEqual(textwrap.dedent(''' + .. oslo.config:group:: DEFAULT + + .. oslo.config:option:: opt_name + + :Type: integer + :Default: ``<None>`` + :Minimum Value: 0 + + ''').lstrip(), results) + def test_with_max(self): results = '\n'.join(list(sphinxext._format_group( app=mock.Mock(), @@ -113,6 +135,28 @@ class FormatGroupTest(base.BaseTestCase): ''').lstrip(), results) + def test_with_max_0(self): + results = '\n'.join(list(sphinxext._format_group( + app=mock.Mock(), + namespace=None, + group_name=None, + group_obj=None, + opt_list=[ + cfg.IntOpt('opt_name', + max=0), + ], + ))) + self.assertEqual(textwrap.dedent(''' + .. oslo.config:group:: DEFAULT + + .. oslo.config:option:: opt_name + + :Type: integer + :Default: ``<None>`` + :Maximum Value: 0 + + ''').lstrip(), results) + def test_with_choices(self): results = '\n'.join(list(sphinxext._format_group( app=mock.Mock(), |