summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2022-12-12 17:28:12 +0000
committerStephen Finucane <stephenfin@redhat.com>2022-12-12 17:49:26 +0000
commit1d8a06da78ed16ed29cdc3b153d67ec1961b57bf (patch)
tree0670d073fd69a700f0b8587a594c0747abc3fcbc
parent2af1d0c51431b3a773e1e52158b9cf43e4645fdd (diff)
downloadpython-novaclient-1d8a06da78ed16ed29cdc3b153d67ec1961b57bf.tar.gz
tests: Fix Python 3.11 compatibility
The argparse lib in Python 3.11 will not allow you to register a subparser more than once with the same name. We were inadvertently doing this in two of our unit tests as part of our check for version handling. There's no need for this. Stop doing it and simply create a new parser each time. An unnecessary check is removed from one of the tests since it confuses matters. Change-Id: I93827f84c456c9f6960e30e2424b67947254752c Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
-rw-r--r--novaclient/tests/unit/test_shell.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/novaclient/tests/unit/test_shell.py b/novaclient/tests/unit/test_shell.py
index a997b23f..f46d0ad6 100644
--- a/novaclient/tests/unit/test_shell.py
+++ b/novaclient/tests/unit/test_shell.py
@@ -777,6 +777,8 @@ class ShellTest(utils.TestCase):
class TestLoadVersionedActions(utils.TestCase):
def test_load_versioned_actions(self):
+ # first load with API version 2.15, ensuring we use the 2.15 version of
+ # the underlying function (which returns 1)
parser = novaclient.shell.NovaClientArgumentParser()
subparsers = parser.add_subparsers(metavar='<subcommand>')
shell = novaclient.shell.OpenStackComputeShell()
@@ -787,6 +789,12 @@ class TestLoadVersionedActions(utils.TestCase):
self.assertEqual(
1, shell.subcommands['fake-action'].get_default('func')())
+ # now load with API version 2.25, ensuring we now use the
+ # correspponding version of the underlying function (which now returns
+ # 2)
+ parser = novaclient.shell.NovaClientArgumentParser()
+ subparsers = parser.add_subparsers(metavar='<subcommand>')
+ shell = novaclient.shell.OpenStackComputeShell()
shell.subcommands = {}
shell._find_actions(subparsers, fake_actions_module,
api_versions.APIVersion("2.25"), False)
@@ -794,10 +802,6 @@ class TestLoadVersionedActions(utils.TestCase):
self.assertEqual(
2, shell.subcommands['fake-action'].get_default('func')())
- self.assertIn('fake-action2', shell.subcommands.keys())
- self.assertEqual(
- 3, shell.subcommands['fake-action2'].get_default('func')())
-
def test_load_versioned_actions_not_in_version_range(self):
parser = novaclient.shell.NovaClientArgumentParser()
subparsers = parser.add_subparsers(metavar='<subcommand>')
@@ -908,6 +912,10 @@ class TestLoadVersionedActions(utils.TestCase):
mock_add_arg.reset_mock()
+ parser = novaclient.shell.NovaClientArgumentParser(add_help=False)
+ subparsers = parser.add_subparsers(metavar='<subcommand>')
+ shell = novaclient.shell.OpenStackComputeShell()
+ shell.subcommands = {}
shell._find_actions(subparsers, fake_actions_module,
api_versions.APIVersion("2.21"), False)
self.assertNotIn(mock.call('--foo', help="first foo"),