Skip to content

Commit ac0f055

Browse files
committed
Add tests for herald
1 parent 7f09ab4 commit ac0f055

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/plugin_tests/test_herald.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from unittest.mock import MagicMock
2+
3+
import pytest
4+
5+
from cloudbot.event import Event
6+
from plugins import herald
7+
from tests.util import wrap_hook_response
8+
9+
10+
@pytest.fixture()
11+
def clear_cache():
12+
try:
13+
yield
14+
finally:
15+
herald.herald_cache.clear()
16+
17+
18+
@pytest.fixture()
19+
def unset_timeout():
20+
try:
21+
yield
22+
finally:
23+
herald.floodcheck.clear()
24+
25+
26+
@pytest.mark.usefixtures("unset_timeout")
27+
class TestWelcome:
28+
def _run(self):
29+
conn = MagicMock()
30+
event = Event(
31+
hook=MagicMock(),
32+
bot=conn.bot,
33+
conn=conn,
34+
channel='#foo',
35+
nick='foobaruser'
36+
)
37+
return wrap_hook_response(herald.welcome, event)
38+
39+
def test_no_herald(self):
40+
result = self._run()
41+
assert result == []
42+
43+
@pytest.mark.parametrize('text,out', [
44+
('Hello world', '\u200b Hello world'),
45+
('bino', '\u200b flenny'),
46+
('\u200b hi', '\u200b \u200b hi'),
47+
('o\u200b<', 'DECOY DUCK --> o\u200b<'),
48+
])
49+
def test_char_strip(self, clear_cache, text, out):
50+
herald.herald_cache['#foo']['foobaruser'] = text
51+
result = self._run()
52+
assert result == [('message', ('#foo', out))]

0 commit comments

Comments
 (0)