Skip to content

Commit efcf589

Browse files
committed
Fix bot client tests
1 parent c777bdb commit efcf589

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

cloudbot/bot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,6 @@ def add_hook(hook, _event):
419419
tasks.sort(key=lambda t: t[0].priority)
420420

421421
for _hook, _event in tasks:
422-
async_util.wrap_future(self.plugin_manager.launch(_hook, _event))
422+
async_util.wrap_future(
423+
self.plugin_manager.launch(_hook, _event), loop=self.loop
424+
)

tests/core_tests/irc_client_test.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import asyncio
22
import logging
33
import socket
4-
from asyncio import Task
5-
from unittest.mock import MagicMock, call, patch
4+
from unittest.mock import call, patch
5+
from unittest.mock import MagicMock
66

77
import pytest
88

@@ -17,13 +17,11 @@ def _filter_event(self, event):
1717
return {k: v for k, v in dict(event).items() if not callable(v)}
1818

1919
def test_data_received(self):
20-
conn, out, proto = self.make_proto()
20+
_, out, proto = self.make_proto()
2121
proto.data_received(
2222
b":server.host COMMAND this is :a command\r\n:server.host PRIVMSG me :hi\r\n"
2323
)
2424

25-
conn.loop.run_until_complete(asyncio.gather(*Task.all_tasks(conn.loop)))
26-
2725
assert out == [
2826
{
2927
"chan": "server.host",
@@ -68,24 +66,22 @@ def test_data_received(self):
6866
def make_proto(self):
6967
conn = MagicMock()
7068
conn.nick = "me"
71-
conn.loop = asyncio.get_event_loop_policy().new_event_loop()
69+
conn.loop = conn.bot.loop = asyncio.get_event_loop_policy().new_event_loop()
7270
out = []
7371

74-
async def func(e):
72+
def func(e):
7573
out.append(self._filter_event(e))
7674

7775
conn.bot.process = func
7876
proto = irc._IrcProtocol(conn)
7977
return conn, out, proto
8078

8179
def test_broken_line_doesnt_interrupt(self):
82-
conn, out, proto = self.make_proto()
80+
_, out, proto = self.make_proto()
8381
proto.data_received(
8482
b":server.host COMMAND this is :a command\r\nPRIVMSG\r\n:server.host PRIVMSG me :hi\r\n"
8583
)
8684

87-
conn.loop.run_until_complete(asyncio.gather(*Task.all_tasks(conn.loop)))
88-
8985
assert out == [
9086
{
9187
"chan": "server.host",

0 commit comments

Comments
 (0)