Skip to content

Commit

Permalink
Fix plugin loading
Browse files Browse the repository at this point in the history
After the switch to importlib, plugins are retrieved by name,
not integer index.
For details see importlib.metadata.EntryPoints.__getitem__()

Also update the mock.patch to match: entry_points() -> EntryPoints
  • Loading branch information
edwagner committed Mar 6, 2024
1 parent 15f8c23 commit b300bfb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 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
11 changes: 10 additions & 1 deletion 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,7 +20,9 @@ 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)
Expand Down

0 comments on commit b300bfb

Please sign in to comment.