Skip to content

Commit

Permalink
test: add regression test for PyFilePlugin folders w/submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
dgw committed Oct 20, 2024
1 parent 86efe41 commit 54372e6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/plugins/test_plugins_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,45 @@ def test_get_label_entrypoint(plugin_tmpfile):
assert meta['label'] == 'plugin label'
assert meta['type'] == handlers.EntryPointPlugin.PLUGIN_TYPE
assert meta['source'] == 'test_plugin = file_mod'


MOCK_PARENT_MODULE = """
from sopel import plugin
from .sub import foo
@plugin.command('mock')
def mock(bot, trigger):
bot.say(foo)
"""

MOCK_SUB_MODULE = """
foo = 'bar baz'
"""


@pytest.fixture
def plugin_folder(tmp_path):
root = tmp_path / 'test_folder_plugin'
root.mkdir()

parent = root / '__init__.py'
with open(parent, 'w') as f:
f.write(MOCK_PARENT_MODULE)

submodule = root / 'sub.py'
with open(submodule, 'w') as f:
f.write(MOCK_SUB_MODULE)

return str(root)


def test_folder_plugin_imports(plugin_folder):
"""Ensure submodule imports work as expected in folder plugins.
Regression test for https://github.com/sopel-irc/sopel/issues/2619
"""
handler = handlers.PyFilePlugin(plugin_folder)
handler.load()
assert handler.module.foo == 'bar baz'

0 comments on commit 54372e6

Please sign in to comment.