Skip to content

Commit 54372e6

Browse files
committed
test: add regression test for PyFilePlugin folders w/submodules
1 parent 86efe41 commit 54372e6

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/plugins/test_plugins_handlers.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,45 @@ def test_get_label_entrypoint(plugin_tmpfile):
100100
assert meta['label'] == 'plugin label'
101101
assert meta['type'] == handlers.EntryPointPlugin.PLUGIN_TYPE
102102
assert meta['source'] == 'test_plugin = file_mod'
103+
104+
105+
MOCK_PARENT_MODULE = """
106+
from sopel import plugin
107+
108+
from .sub import foo
109+
110+
111+
@plugin.command('mock')
112+
def mock(bot, trigger):
113+
bot.say(foo)
114+
"""
115+
116+
MOCK_SUB_MODULE = """
117+
foo = 'bar baz'
118+
"""
119+
120+
121+
@pytest.fixture
122+
def plugin_folder(tmp_path):
123+
root = tmp_path / 'test_folder_plugin'
124+
root.mkdir()
125+
126+
parent = root / '__init__.py'
127+
with open(parent, 'w') as f:
128+
f.write(MOCK_PARENT_MODULE)
129+
130+
submodule = root / 'sub.py'
131+
with open(submodule, 'w') as f:
132+
f.write(MOCK_SUB_MODULE)
133+
134+
return str(root)
135+
136+
137+
def test_folder_plugin_imports(plugin_folder):
138+
"""Ensure submodule imports work as expected in folder plugins.
139+
140+
Regression test for https://github.com/sopel-irc/sopel/issues/2619
141+
"""
142+
handler = handlers.PyFilePlugin(plugin_folder)
143+
handler.load()
144+
assert handler.module.foo == 'bar baz'

0 commit comments

Comments
 (0)