Skip to content

Commit da5acdc

Browse files
committed
Error on duplicate WizardObjectPlugins
1 parent 1474c8d commit da5acdc

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎paths_cli/tests/wizard/test_plugin_classes.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,12 @@ def test_register_plugin(self):
290290
self.wrapper.register_plugin(self.plugin_no_format)
291291
assert len(self.wrapper.choices) == 1
292292
assert self.wrapper.choices['bar'] == self.plugin_no_format
293-
# TODO: what is the desired behavior if more that one plugin tries
294-
# to register with the same name? override or error? currently
295-
# overrides, but that should not be considered API
293+
294+
def test_register_plugin_duplicate(self):
295+
self.wrapper.choices['bar'] = self.plugin_no_format
296+
with pytest.raises(WizardObjectPluginRegistrationError,
297+
match="already been registered"):
298+
self.wrapper.register_plugin(self.plugin_format)
296299

297300
@pytest.mark.parametrize('input_type', ['method', 'format', 'string'])
298301
def test_get_ask(self, input_type):

‎paths_cli/wizard/plugin_classes.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
from paths_cli.wizard.parameters import WizardParameter
66
from paths_cli.wizard.helper import Helper
77

8+
9+
class WizardObjectPluginRegistrationError(Exception):
10+
pass
11+
12+
813
_PLUGIN_DOCSTRING = """
914
requires_ops : Tuple[int, int]
1015
version of OpenPathSampling required for this plugin
@@ -360,6 +365,11 @@ def register_plugin(self, plugin):
360365
plugin : :class:`.WizardObjectPlugin`
361366
the plugin to register
362367
"""
368+
if plugin.name in self.choices:
369+
raise WizardObjectPluginRegistrationError(
370+
f"A plugin named '{plugin.name}' has already been "
371+
f"registered with the category '{self.name}'"
372+
)
363373
self.choices[plugin.name] = plugin
364374

365375
def _get_intro(self, wizard, context):

0 commit comments

Comments
 (0)