From a5fd1fe60aaebc791c85f957fa34ed31e37f5f33 Mon Sep 17 00:00:00 2001 From: dgw Date: Thu, 12 Sep 2024 02:28:51 -0500 Subject: [PATCH] test: add regression test for `PyFilePlugin` folders w/submodules --- test/plugins/test_plugins_handlers.py | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/plugins/test_plugins_handlers.py b/test/plugins/test_plugins_handlers.py index f34035369..8e6eedd45 100644 --- a/test/plugins/test_plugins_handlers.py +++ b/test/plugins/test_plugins_handlers.py @@ -100,3 +100,44 @@ 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()