From 78098e6b18026ff9ef03a948b57348f02d42e13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Tue, 2 Aug 2022 16:28:53 +0200 Subject: [PATCH] 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 --- oslo_config/tests/test_cfg.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/oslo_config/tests/test_cfg.py b/oslo_config/tests/test_cfg.py index 60032e6d..16ec21d2 100644 --- a/oslo_config/tests/test_cfg.py +++ b/oslo_config/tests/test_cfg.py @@ -207,8 +207,8 @@ class HelpTestCase(BaseTestCase): self.conf([]) self.conf.print_help(file=f) self.assertIn( - 'usage: test [-h] [--aa AA] [--bb BB] [--cc CC] [--config-dir DIR]' - '\n [--config-file PATH] [--version]', + 'usage: test [-h] [--aa AA] [--bb BB] [--cc CC] ' + '[--config-dir DIR]', f.getvalue()) # argparse may generate two different help messages: # - In Python >=3.10: "options:\n --version" @@ -5074,14 +5074,13 @@ class DeprecationWarningTests(DeprecationWarningTestBase): def assert_message_logged(self, deprecated_name, deprecated_group, current_name, current_group): - expected = (cfg._Namespace._deprecated_opt_message % + expected = ('Deprecated: ' + cfg._Namespace._deprecated_opt_message % {'dep_option': deprecated_name, 'dep_group': deprecated_group, 'option': current_name, 'group': current_group} ) - self.assertEqual(self.log_prefix + expected + '\n', - self.log_fixture.output) + self.assertEqual(expected + '\n', self.log_fixture.output) def test_deprecated_for_removal(self): self.conf.register_opt(cfg.StrOpt('foo', @@ -5097,10 +5096,10 @@ class DeprecationWarningTests(DeprecationWarningTestBase): self.assertEqual('bar', self.conf.foo) # Options not set in the config should not be logged. self.assertIsNone(self.conf.bar) - expected = ('Option "foo" from group "DEFAULT" is deprecated for ' - 'removal. Its value may be silently ignored in the ' - 'future.\n') - self.assertEqual(self.log_prefix + expected, self.log_fixture.output) + expected = ('Deprecated: Option "foo" from group "DEFAULT" is ' + 'deprecated for removal. Its value may be silently ' + 'ignored in the future.\n') + self.assertEqual(expected, self.log_fixture.output) def test_deprecated_for_removal_with_group(self): self.conf.register_group(cfg.OptGroup('other')) @@ -5119,10 +5118,10 @@ class DeprecationWarningTests(DeprecationWarningTestBase): self.assertEqual('bar', self.conf.other.foo) # Options not set in the config should not be logged. self.assertIsNone(self.conf.other.bar) - expected = ('Option "foo" from group "other" is deprecated for ' - 'removal. Its value may be silently ignored in the ' - 'future.\n') - self.assertEqual(self.log_prefix + expected, self.log_fixture.output) + expected = ('Deprecated: Option "foo" from group "other" is ' + 'deprecated for removal. Its value may be silently ' + 'ignored in the future.\n') + self.assertEqual(expected, self.log_fixture.output) def test_deprecated_with_dest(self): self.conf.register_group(cfg.OptGroup('other')) @@ -5136,12 +5135,12 @@ class DeprecationWarningTests(DeprecationWarningTestBase): self.conf(['--config-file', paths[0]]) self.assertEqual('baz', self.conf.other.foo) - expected = (cfg._Namespace._deprecated_opt_message % + expected = ('Deprecated: ' + cfg._Namespace._deprecated_opt_message % {'dep_option': 'bar', 'dep_group': 'other', 'option': 'foo-bar', 'group': 'other'} + '\n') - self.assertEqual(self.log_prefix + expected, self.log_fixture.output) + self.assertEqual(expected, self.log_fixture.output) class DeprecationWarningTestsNoOsloLog(DeprecationWarningTests):