Skip to content

Commit

Permalink
Fix bot client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed Jun 28, 2020
1 parent c777bdb commit efcf589
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 3 additions & 1 deletion cloudbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,6 @@ def add_hook(hook, _event):
tasks.sort(key=lambda t: t[0].priority)

for _hook, _event in tasks:
async_util.wrap_future(self.plugin_manager.launch(_hook, _event))
async_util.wrap_future(
self.plugin_manager.launch(_hook, _event), loop=self.loop
)
16 changes: 6 additions & 10 deletions tests/core_tests/irc_client_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
import logging
import socket
from asyncio import Task
from unittest.mock import MagicMock, call, patch
from unittest.mock import call, patch
from unittest.mock import MagicMock

import pytest

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

def test_data_received(self):
conn, out, proto = self.make_proto()
_, out, proto = self.make_proto()
proto.data_received(
b":server.host COMMAND this is :a command\r\n:server.host PRIVMSG me :hi\r\n"
)

conn.loop.run_until_complete(asyncio.gather(*Task.all_tasks(conn.loop)))

assert out == [
{
"chan": "server.host",
Expand Down Expand Up @@ -68,24 +66,22 @@ def test_data_received(self):
def make_proto(self):
conn = MagicMock()
conn.nick = "me"
conn.loop = asyncio.get_event_loop_policy().new_event_loop()
conn.loop = conn.bot.loop = asyncio.get_event_loop_policy().new_event_loop()
out = []

async def func(e):
def func(e):
out.append(self._filter_event(e))

conn.bot.process = func
proto = irc._IrcProtocol(conn)
return conn, out, proto

def test_broken_line_doesnt_interrupt(self):
conn, out, proto = self.make_proto()
_, out, proto = self.make_proto()
proto.data_received(
b":server.host COMMAND this is :a command\r\nPRIVMSG\r\n:server.host PRIVMSG me :hi\r\n"
)

conn.loop.run_until_complete(asyncio.gather(*Task.all_tasks(conn.loop)))

assert out == [
{
"chan": "server.host",
Expand Down

0 comments on commit efcf589

Please sign in to comment.