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

Use full plugin_name when finding chosen reader rather than startswith #297

Merged
merged 6 commits into from
Jun 16, 2023
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/npe2/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _read(
_pm = PluginManager.instance()

for rdr in _pm.iter_compatible_readers(paths):
if plugin_name and not rdr.command.startswith(plugin_name):
if plugin_name and rdr.plugin_name != plugin_name:
continue
read_func = rdr.exec(
kwargs={"path": paths, "stack": stack, "_registry": _pm.commands}
Expand Down
29 changes: 29 additions & 0 deletions tests/test__io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,35 @@ def test_read_with_no_plugin():
read(["some.nope"], stack=False)


def test_read_uses_correct_passed_plugin(tmp_path):
pm = PluginManager()
long_name = "gooby-again"
short_name = "gooby"
long_name_plugin = DynamicPlugin(long_name, plugin_manager=pm)
short_name_plugin = DynamicPlugin(short_name, plugin_manager=pm)

path = "something.fzzy"
mock_file = tmp_path / path
mock_file.touch()

@long_name_plugin.contribute.reader(filename_patterns=["*.fzzy"])
def get_read_long(path=mock_file):
raise ValueError(
f"Uhoh, {long_name} was chosen, but given plugin was {short_name}"
)

@short_name_plugin.contribute.reader(filename_patterns=["*.fzzy"])
def get_read(path=mock_file):
def read(paths):
return [(None,)]

return read

# "gooby-again" isn't used even though given plugin starts with the same name
# if an error is thrown here, it means we selected the wrong plugin
io_utils._read(["some.fzzy"], plugin_name=short_name, stack=False, _pm=pm)


def test_read_return_reader(uses_sample_plugin):
data, reader = read_get_reader("some.fzzy")
assert data == [(None,)]
Expand Down