Skip to content

Commit adb4a31

Browse files
committed
module: prevent new decorators to be available in sopel.module
1 parent 0884d94 commit adb4a31

File tree

7 files changed

+123
-78
lines changed

7 files changed

+123
-78
lines changed

sopel/module.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,36 @@
88
"""
99
from __future__ import absolute_import, division, print_function, unicode_literals
1010

11-
from sopel.plugin import * # noqa
11+
# Import everything from sopel.plugin at the time of replacement.
12+
# Everything new from this point on must *not* leak here.
13+
# Therefore, don't add anything to this import list. Ever.
14+
from sopel.plugin import ( # noqa
15+
ADMIN,
16+
action_commands,
17+
commands,
18+
echo,
19+
event,
20+
example,
21+
HALFOP,
22+
intent,
23+
interval,
24+
nickname_commands,
25+
NOLIMIT,
26+
OP,
27+
OPER,
28+
output_prefix,
29+
OWNER,
30+
priority,
31+
rate,
32+
require_account,
33+
require_admin,
34+
require_chanmsg,
35+
require_owner,
36+
require_privilege,
37+
require_privmsg,
38+
rule,
39+
thread,
40+
unblockable,
41+
url,
42+
VOICE,
43+
)

sopel/modules/reddit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import requests
2121

2222
from sopel.formatting import bold, color, colors
23-
from sopel.module import commands, example, find, NOLIMIT, OP, require_chanmsg, url
23+
from sopel.module import commands, example, NOLIMIT, OP, require_chanmsg, url
24+
from sopel.plugin import find
2425
from sopel.tools import time
2526
from sopel.tools.web import USER_AGENT
2627

test/plugins/test_plugins_rules.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88

9-
from sopel import bot, loader, module, trigger
9+
from sopel import bot, loader, module, plugin, trigger
1010
from sopel.plugins import rules
1111
from sopel.tests import rawlist
1212

@@ -851,7 +851,7 @@ def handler(wrapped, trigger):
851851
def test_kwargs_from_callable_label(mockbot):
852852
# prepare callable
853853
@module.rule(r'hello', r'hi', r'hey', r'hello|hi')
854-
@module.label('hello_rule')
854+
@plugin.label('hello_rule')
855855
def handler(wrapped, trigger):
856856
wrapped.reply('Hi!')
857857

@@ -2182,7 +2182,7 @@ def test_find_rule_parse_pattern():
21822182

21832183
def test_find_rule_from_callable(mockbot):
21842184
# prepare callable
2185-
@module.find(r'hello', r'hi', r'hey', r'hello|hi')
2185+
@plugin.find(r'hello', r'hi', r'hey', r'hello|hi')
21862186
def handler(wrapped, trigger):
21872187
wrapped.reply('Hi!')
21882188

@@ -2269,7 +2269,7 @@ def test_search_rule_parse_pattern():
22692269

22702270
def test_search_rule_from_callable(mockbot):
22712271
# prepare callable
2272-
@module.search(r'hello', r'hi', r'hey', r'hello|hi')
2272+
@plugin.search(r'hello', r'hi', r'hey', r'hello|hi')
22732273
def handler(wrapped, trigger):
22742274
wrapped.reply('Hi!')
22752275

test/test_bot.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88

9-
from sopel import bot, loader, module, plugins, trigger
9+
from sopel import bot, loader, module, plugin, plugins, trigger
1010
from sopel.plugins import rules
1111
from sopel.tests import rawlist
1212
from sopel.tools import Identifier, SopelMemory
@@ -293,41 +293,41 @@ def test_register_unregister_plugin(tmpconfig, mockplugin):
293293
def test_remove_plugin_unknown_plugin(tmpconfig):
294294
sopel = bot.Sopel(tmpconfig, daemon=False)
295295

296-
plugin = plugins.handlers.PyModulePlugin('admin', 'sopel.modules')
296+
handler = plugins.handlers.PyModulePlugin('admin', 'sopel.modules')
297297
with pytest.raises(plugins.exceptions.PluginNotRegistered):
298-
sopel.remove_plugin(plugin, [], [], [], [])
298+
sopel.remove_plugin(handler, [], [], [], [])
299299

300300

301301
def test_remove_plugin_unregistered_plugin(tmpconfig):
302302
sopel = bot.Sopel(tmpconfig, daemon=False)
303303

304304
# register the plugin
305-
plugin = plugins.handlers.PyModulePlugin('coretasks', 'sopel')
306-
plugin.load()
307-
plugin.register(sopel)
305+
handler = plugins.handlers.PyModulePlugin('coretasks', 'sopel')
306+
handler.load()
307+
handler.register(sopel)
308308

309309
# Unregister the plugin
310-
plugin.unregister(sopel)
310+
handler.unregister(sopel)
311311

312312
# And now it must raise an exception
313313
with pytest.raises(plugins.exceptions.PluginNotRegistered):
314-
sopel.remove_plugin(plugin, [], [], [], [])
314+
sopel.remove_plugin(handler, [], [], [], [])
315315

316316

317317
def test_reload_plugin_unregistered_plugin(tmpconfig):
318318
sopel = bot.Sopel(tmpconfig, daemon=False)
319319

320320
# register the plugin
321-
plugin = plugins.handlers.PyModulePlugin('coretasks', 'sopel')
322-
plugin.load()
323-
plugin.register(sopel)
321+
handler = plugins.handlers.PyModulePlugin('coretasks', 'sopel')
322+
handler.load()
323+
handler.register(sopel)
324324

325325
# Unregister the plugin
326-
plugin.unregister(sopel)
326+
handler.unregister(sopel)
327327

328328
# And now it must raise an exception
329329
with pytest.raises(plugins.exceptions.PluginNotRegistered):
330-
sopel.reload_plugin(plugin.name)
330+
sopel.reload_plugin(handler.name)
331331

332332

333333
# -----------------------------------------------------------------------------
@@ -340,11 +340,11 @@ def test_register_callables(tmpconfig):
340340
def rule_hello(bot, trigger):
341341
pass
342342

343-
@module.find(r'(hi|hello|hey|sup)')
343+
@plugin.find(r'(hi|hello|hey|sup)')
344344
def rule_find_hello(bot, trigger):
345345
pass
346346

347-
@module.search(r'(hi|hello|hey|sup)')
347+
@plugin.search(r'(hi|hello|hey|sup)')
348348
def rule_search_hello(bot, trigger):
349349
pass
350350

@@ -382,7 +382,7 @@ def mixed_rule_command(bot, trigger):
382382
pass
383383

384384
@module.event('JOIN')
385-
@module.label('handle_join_event')
385+
@plugin.label('handle_join_event')
386386
def on_join(bot, trigger):
387387
pass
388388

test/test_module.py

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# coding=utf-8
2-
"""Tests for message formatting"""
2+
"""Tests for sopel.module decorators
3+
4+
.. important::
5+
6+
These tests are kept here as a proof that ``sopel.module`` is backward
7+
compatible up to Sopel 9, when it will be removed.
8+
9+
"""
310
from __future__ import absolute_import, division, print_function, unicode_literals
411

512
import pytest
@@ -123,52 +130,6 @@ def mock(bot, trigger, match):
123130
assert mock.rule == [r'\w+', '.*', r'\d+']
124131

125132

126-
def test_find():
127-
@module.find('.*')
128-
def mock(bot, trigger, match):
129-
return True
130-
assert mock.find_rules == ['.*']
131-
132-
133-
def test_find_args():
134-
@module.find('.*', r'\d+')
135-
def mock(bot, trigger, match):
136-
return True
137-
assert mock.find_rules == ['.*', r'\d+']
138-
139-
140-
def test_find_multiple():
141-
@module.find('.*', r'\d+')
142-
@module.find('.*')
143-
@module.find(r'\w+')
144-
def mock(bot, trigger, match):
145-
return True
146-
assert mock.find_rules == [r'\w+', '.*', r'\d+']
147-
148-
149-
def test_search():
150-
@module.search('.*')
151-
def mock(bot, trigger, match):
152-
return True
153-
assert mock.search_rules == ['.*']
154-
155-
156-
def test_search_args():
157-
@module.search('.*', r'\d+')
158-
def mock(bot, trigger, match):
159-
return True
160-
assert mock.search_rules == ['.*', r'\d+']
161-
162-
163-
def test_search_multiple():
164-
@module.search('.*', r'\d+')
165-
@module.search('.*')
166-
@module.search(r'\w+')
167-
def mock(bot, trigger, match):
168-
return True
169-
assert mock.search_rules == [r'\w+', '.*', r'\d+']
170-
171-
172133
def test_thread():
173134
@module.thread(True)
174135
def mock(bot, trigger, match):
@@ -326,13 +287,6 @@ def mock(bot, trigger, match):
326287
assert not hasattr(mock, 'rule')
327288

328289

329-
def test_label():
330-
@module.label('hello')
331-
def mock(bot, trigger):
332-
return True
333-
assert mock.rule_label == 'hello'
334-
335-
336290
def test_priority():
337291
@module.priority('high')
338292
def mock(bot, trigger, match):

test/test_plugin.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# coding=utf-8
2+
"""Tests for sopel.plugin decorators"""
3+
from __future__ import absolute_import, division, print_function, unicode_literals
4+
5+
from sopel import plugin
6+
7+
8+
def test_find():
9+
@plugin.find('.*')
10+
def mock(bot, trigger, match):
11+
return True
12+
assert mock.find_rules == ['.*']
13+
14+
15+
def test_find_args():
16+
@plugin.find('.*', r'\d+')
17+
def mock(bot, trigger, match):
18+
return True
19+
assert mock.find_rules == ['.*', r'\d+']
20+
21+
22+
def test_find_multiple():
23+
@plugin.find('.*', r'\d+')
24+
@plugin.find('.*')
25+
@plugin.find(r'\w+')
26+
def mock(bot, trigger, match):
27+
return True
28+
assert mock.find_rules == [r'\w+', '.*', r'\d+']
29+
30+
31+
def test_label():
32+
@plugin.label('hello')
33+
def mock(bot, trigger):
34+
return True
35+
assert mock.rule_label == 'hello'
36+
37+
38+
def test_search():
39+
@plugin.search('.*')
40+
def mock(bot, trigger, match):
41+
return True
42+
assert mock.search_rules == ['.*']
43+
44+
45+
def test_search_args():
46+
@plugin.search('.*', r'\d+')
47+
def mock(bot, trigger, match):
48+
return True
49+
assert mock.search_rules == ['.*', r'\d+']
50+
51+
52+
def test_search_multiple():
53+
@plugin.search('.*', r'\d+')
54+
@plugin.search('.*')
55+
@plugin.search(r'\w+')
56+
def mock(bot, trigger, match):
57+
return True
58+
assert mock.search_rules == [r'\w+', '.*', r'\d+']

test/tools/test_tools_jobs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88

9-
from sopel import loader, module
9+
from sopel import loader, module, plugin
1010
from sopel.tools import jobs
1111

1212

@@ -201,7 +201,7 @@ def test_job_next_many():
201201

202202
def test_job_from_callable(mockconfig):
203203
@module.interval(5)
204-
@module.label('testjob')
204+
@plugin.label('testjob')
205205
def handler(manager):
206206
"""The job's docstring."""
207207
return 'tested'

0 commit comments

Comments
 (0)