Merge "Incorrect group name when deprecated_group is not specified"

This commit is contained in:
Jenkins 2016-05-24 21:12:39 +00:00 committed by Gerrit Code Review
commit e7b6cef9db
4 changed files with 52 additions and 19 deletions

View File

@ -160,7 +160,7 @@ class _OptFormatter(object):
lines = ['[%s]\n' % groupname]
self.writelines(lines)
def format(self, opt):
def format(self, opt, group_name):
"""Format a description of an option to the output file.
:param opt: a cfg.Opt instance
@ -221,7 +221,7 @@ class _OptFormatter(object):
for d in opt.deprecated_opts:
lines.append('# Deprecated group/name - [%s]/%s\n' %
(d.group or 'DEFAULT', d.name or opt.dest))
(d.group or group_name, d.name or opt.dest))
if opt.deprecated_for_removal:
lines.append(
@ -361,7 +361,7 @@ def _output_opts(f, group, group_data):
for opt in opts:
f.write('\n')
try:
f.format(opt)
f.format(opt, group)
except Exception as err:
f.write('# Warning: Failed to format sample for %s\n' %
(opt.dest,))

View File

@ -154,7 +154,7 @@ def _format_group(app, namespace, group_name, group_obj, opt_list):
if opt.deprecated_opts:
for line in _list_table(
['Group', 'Name'],
((d.group or 'DEFAULT',
((d.group or group_name,
d.name or opt.dest or 'UNSET')
for d in opt.deprecated_opts),
title='Deprecated Variations'):

View File

@ -80,9 +80,8 @@ class GeneratorTestCase(base.BaseTestCase):
default='a',
choices=(None, '', 'a', 'b', 'c'),
help='a string with choices'),
'deprecated_opt': cfg.StrOpt('bar',
deprecated_name='foobar',
help='deprecated'),
'deprecated_opt_without_deprecated_group': cfg.StrOpt(
'bar', deprecated_name='foobar', help='deprecated'),
'deprecated_for_removal_opt': cfg.StrOpt(
'bar', deprecated_for_removal=True, help='deprecated for removal'),
'deprecated_reason_opt': cfg.BoolOpt(
@ -92,10 +91,9 @@ class GeneratorTestCase(base.BaseTestCase):
deprecated_reason='This was supposed to work but it really, '
'really did not. Always buy house insurance.',
help='DEPRECATED: Turn off stove'),
'deprecated_group': cfg.StrOpt('bar',
deprecated_group='group1',
deprecated_name='foobar',
help='deprecated'),
'deprecated_opt_with_deprecated_group': cfg.StrOpt(
'bar', deprecated_name='foobar', deprecated_group='group1',
help='deprecated'),
# Unknown Opt default must be a string
'unknown_type': cfg.Opt('unknown_opt',
default='123',
@ -398,8 +396,10 @@ class GeneratorTestCase(base.BaseTestCase):
# Allowed values: <None>, '', a, b, c
#choices_opt = a
''')),
('deprecated',
dict(opts=[('test', [(groups['foo'], [opts['deprecated_opt']])])],
('deprecated opt without deprecated group',
dict(opts=[('test',
[(groups['foo'],
[opts['deprecated_opt_without_deprecated_group']])])],
expected='''[DEFAULT]
@ -411,7 +411,7 @@ class GeneratorTestCase(base.BaseTestCase):
#
# deprecated (string value)
# Deprecated group/name - [DEFAULT]/foobar
# Deprecated group/name - [foo]/foobar
#bar = <None>
''')),
('deprecated_for_removal',
@ -452,8 +452,10 @@ class GeneratorTestCase(base.BaseTestCase):
# Always buy house insurance.
#turn_off_stove = false
''')),
('deprecated_group',
dict(opts=[('test', [(groups['foo'], [opts['deprecated_group']])])],
('deprecated_opt_with_deprecated_group',
dict(opts=[('test',
[(groups['foo'],
[opts['deprecated_opt_with_deprecated_group']])])],
expected='''[DEFAULT]
@ -1010,7 +1012,7 @@ class GeneratorMutableOptionTestCase(base.BaseTestCase):
out = moves.StringIO()
opt = cfg.StrOpt('foo', help='foo option', mutable=True)
gen = generator._OptFormatter(output_file=out)
gen.format(opt)
gen.format(opt, 'group1')
result = out.getvalue()
self.assertIn(
'This option can be changed without restarting.',
@ -1021,7 +1023,7 @@ class GeneratorMutableOptionTestCase(base.BaseTestCase):
out = moves.StringIO()
opt = cfg.StrOpt('foo', help='foo option', mutable=False)
gen = generator._OptFormatter(output_file=out)
gen.format(opt)
gen.format(opt, 'group1')
result = out.getvalue()
self.assertNotIn(
'This option can be changed without restarting.',

View File

@ -219,7 +219,7 @@ class FormatGroupTest(base.BaseTestCase):
''').lstrip(), results)
def test_deprecated_opts(self):
def test_deprecated_opts_without_deprecated_group(self):
results = '\n'.join(list(sphinxext._format_group(
app=mock.Mock(),
namespace=None,
@ -249,6 +249,37 @@ class FormatGroupTest(base.BaseTestCase):
''').lstrip(), results)
def test_deprecated_opts_with_deprecated_group(self):
results = '\n'.join(list(sphinxext._format_group(
app=mock.Mock(),
namespace=None,
group_name=None,
group_obj=None,
opt_list=[
cfg.StrOpt('opt_name',
deprecated_name='deprecated_name',
deprecated_group='deprecated_group',
)
],
)))
self.assertEqual(textwrap.dedent('''
.. oslo.config:group:: DEFAULT
.. oslo.config:option:: opt_name
:Type: string
:Default: ``<None>``
.. list-table:: Deprecated Variations
:header-rows: 1
- * Group
* Name
- * deprecated_group
* deprecated_name
''').lstrip(), results)
def test_deprecated_for_removal(self):
results = '\n'.join(list(sphinxext._format_group(
app=mock.Mock(),