fix CLI mismatch in unit tests
Since cliff > 3.4.0 we can see mismatch errors with unit tests, this patch fix this error. Also this patch fix some issues with deprecation messages. All these issues needs to be fixed together to unlock our gates. Closes-bug: #1908934 Change-Id: I8396b4f3ba74a9ea023bff2e3027710f16a74af4
This commit is contained in:
parent
9eaae04453
commit
78098e6b18
@ -207,8 +207,8 @@ class HelpTestCase(BaseTestCase):
|
|||||||
self.conf([])
|
self.conf([])
|
||||||
self.conf.print_help(file=f)
|
self.conf.print_help(file=f)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'usage: test [-h] [--aa AA] [--bb BB] [--cc CC] [--config-dir DIR]'
|
'usage: test [-h] [--aa AA] [--bb BB] [--cc CC] '
|
||||||
'\n [--config-file PATH] [--version]',
|
'[--config-dir DIR]',
|
||||||
f.getvalue())
|
f.getvalue())
|
||||||
# argparse may generate two different help messages:
|
# argparse may generate two different help messages:
|
||||||
# - In Python >=3.10: "options:\n --version"
|
# - In Python >=3.10: "options:\n --version"
|
||||||
@ -5074,14 +5074,13 @@ class DeprecationWarningTests(DeprecationWarningTestBase):
|
|||||||
|
|
||||||
def assert_message_logged(self, deprecated_name, deprecated_group,
|
def assert_message_logged(self, deprecated_name, deprecated_group,
|
||||||
current_name, current_group):
|
current_name, current_group):
|
||||||
expected = (cfg._Namespace._deprecated_opt_message %
|
expected = ('Deprecated: ' + cfg._Namespace._deprecated_opt_message %
|
||||||
{'dep_option': deprecated_name,
|
{'dep_option': deprecated_name,
|
||||||
'dep_group': deprecated_group,
|
'dep_group': deprecated_group,
|
||||||
'option': current_name,
|
'option': current_name,
|
||||||
'group': current_group}
|
'group': current_group}
|
||||||
)
|
)
|
||||||
self.assertEqual(self.log_prefix + expected + '\n',
|
self.assertEqual(expected + '\n', self.log_fixture.output)
|
||||||
self.log_fixture.output)
|
|
||||||
|
|
||||||
def test_deprecated_for_removal(self):
|
def test_deprecated_for_removal(self):
|
||||||
self.conf.register_opt(cfg.StrOpt('foo',
|
self.conf.register_opt(cfg.StrOpt('foo',
|
||||||
@ -5097,10 +5096,10 @@ class DeprecationWarningTests(DeprecationWarningTestBase):
|
|||||||
self.assertEqual('bar', self.conf.foo)
|
self.assertEqual('bar', self.conf.foo)
|
||||||
# Options not set in the config should not be logged.
|
# Options not set in the config should not be logged.
|
||||||
self.assertIsNone(self.conf.bar)
|
self.assertIsNone(self.conf.bar)
|
||||||
expected = ('Option "foo" from group "DEFAULT" is deprecated for '
|
expected = ('Deprecated: Option "foo" from group "DEFAULT" is '
|
||||||
'removal. Its value may be silently ignored in the '
|
'deprecated for removal. Its value may be silently '
|
||||||
'future.\n')
|
'ignored in the future.\n')
|
||||||
self.assertEqual(self.log_prefix + expected, self.log_fixture.output)
|
self.assertEqual(expected, self.log_fixture.output)
|
||||||
|
|
||||||
def test_deprecated_for_removal_with_group(self):
|
def test_deprecated_for_removal_with_group(self):
|
||||||
self.conf.register_group(cfg.OptGroup('other'))
|
self.conf.register_group(cfg.OptGroup('other'))
|
||||||
@ -5119,10 +5118,10 @@ class DeprecationWarningTests(DeprecationWarningTestBase):
|
|||||||
self.assertEqual('bar', self.conf.other.foo)
|
self.assertEqual('bar', self.conf.other.foo)
|
||||||
# Options not set in the config should not be logged.
|
# Options not set in the config should not be logged.
|
||||||
self.assertIsNone(self.conf.other.bar)
|
self.assertIsNone(self.conf.other.bar)
|
||||||
expected = ('Option "foo" from group "other" is deprecated for '
|
expected = ('Deprecated: Option "foo" from group "other" is '
|
||||||
'removal. Its value may be silently ignored in the '
|
'deprecated for removal. Its value may be silently '
|
||||||
'future.\n')
|
'ignored in the future.\n')
|
||||||
self.assertEqual(self.log_prefix + expected, self.log_fixture.output)
|
self.assertEqual(expected, self.log_fixture.output)
|
||||||
|
|
||||||
def test_deprecated_with_dest(self):
|
def test_deprecated_with_dest(self):
|
||||||
self.conf.register_group(cfg.OptGroup('other'))
|
self.conf.register_group(cfg.OptGroup('other'))
|
||||||
@ -5136,12 +5135,12 @@ class DeprecationWarningTests(DeprecationWarningTestBase):
|
|||||||
|
|
||||||
self.conf(['--config-file', paths[0]])
|
self.conf(['--config-file', paths[0]])
|
||||||
self.assertEqual('baz', self.conf.other.foo)
|
self.assertEqual('baz', self.conf.other.foo)
|
||||||
expected = (cfg._Namespace._deprecated_opt_message %
|
expected = ('Deprecated: ' + cfg._Namespace._deprecated_opt_message %
|
||||||
{'dep_option': 'bar',
|
{'dep_option': 'bar',
|
||||||
'dep_group': 'other',
|
'dep_group': 'other',
|
||||||
'option': 'foo-bar',
|
'option': 'foo-bar',
|
||||||
'group': 'other'} + '\n')
|
'group': 'other'} + '\n')
|
||||||
self.assertEqual(self.log_prefix + expected, self.log_fixture.output)
|
self.assertEqual(expected, self.log_fixture.output)
|
||||||
|
|
||||||
|
|
||||||
class DeprecationWarningTestsNoOsloLog(DeprecationWarningTests):
|
class DeprecationWarningTestsNoOsloLog(DeprecationWarningTests):
|
||||||
|
Loading…
Reference in New Issue
Block a user