Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plugin loading #274

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading