Skip to content

Commit

Permalink
Merge pull request #274 from edwagner/fix-plugin-loading
Browse files Browse the repository at this point in the history
Fix plugin loading
  • Loading branch information
kedder committed Mar 6, 2024
2 parents 15f8c23 + c659d45 commit 273ca39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ofxstatement/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_plugin(name: str, ui: UI, settings: MutableMapping) -> "Plugin":
raise PluginNotRegistered(name)
if len(plugins) > 1:
raise PluginNameConflict(plugins)
plugin = plugins[0].load() # type: ignore[index] # index requires a int but class expects a string
plugin = plugins[name].load()
return plugin(ui, settings)


Expand Down
15 changes: 13 additions & 2 deletions src/ofxstatement/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

import mock

import sys

if sys.version_info < (3, 10):
from importlib_metadata import EntryPoints
else:
from importlib.metadata import EntryPoints

from ofxstatement import plugin


Expand All @@ -13,15 +20,19 @@ def get_parser(self):

ep = mock.Mock()
ep.load.return_value = SamplePlugin
ep_patch = mock.patch("ofxstatement.plugin.entry_points", return_value=[ep])
ep_patch = mock.patch(
"ofxstatement.plugin.entry_points", return_value=EntryPoints([ep])
)
with ep_patch:
p = plugin.get_plugin("sample", mock.Mock("UI"), mock.Mock("Settings"))
self.assertIsInstance(p, SamplePlugin)

def test_get_plugin_conflict(self) -> None:
ep = mock.Mock()

ep_patch = mock.patch("ofxstatement.plugin.entry_points", return_value=[ep, ep])
ep_patch = mock.patch(
"ofxstatement.plugin.entry_points", return_value=EntryPoints([ep, ep])
)
with ep_patch:
with self.assertRaises(plugin.PluginNameConflict):
plugin.get_plugin("conflicting", mock.Mock("UI"), mock.Mock("Settings"))
Expand Down

0 comments on commit 273ca39

Please sign in to comment.