def test_async_plugin(self): bot = self.callFTU(nick='foo', loop=asyncio.new_event_loop()) bot.include('async_command') plugin = bot.get_plugin(command.Commands) mask = utils.IrcString('*****@*****.**') res = plugin.on_command('get', mask, mask.nick, data='') assert isinstance(res, asyncio.Task) res2 = plugin.on_command('get', mask, mask.nick, data='') assert res2 is None plugin.on_command('put', mask, mask.nick, data='xx yy') bot.loop.run_until_complete(res) assert res.result() == ['xx', 'yy']
def __init__(self, **config): self.check_required() if "loop" not in config: loop = asyncio.new_event_loop() loop = mock.create_autospec(loop, spec_set=True) loop.call_later = call_later loop.call_soon = call_soon loop.time.return_value = 10 config.update(testing=True, async=False, level=1000, loop=loop) else: config.update(testing=True, level=1000) super(IrcBot, self).__init__(**config) self.protocol = irc3.IrcConnection() self.protocol.closed = False self.protocol.factory = self self.protocol.transport = MagicMock() self.protocol.write = MagicMock()
def __init__(self, **config): self.check_required() if 'loop' not in config: loop = asyncio.new_event_loop() loop = mock.create_autospec(loop, spec_set=True) loop.call_later = call_later loop.call_soon = call_soon loop.time.return_value = 10 config.update(testing=True, async=False, level=1000, loop=loop) else: config.update(testing=True, level=1000) super(IrcBot, self).__init__(**config) self.protocol = irc3.IrcConnection() self.protocol.closed = False self.protocol.factory = self self.protocol.transport = MagicMock() self.protocol.write = MagicMock()
def test_async_event(self): loop = asyncio.new_event_loop() future = asyncio.Future(loop=loop) @asyncio.coroutine def e(ctx, **kwargs): ctx.privmsg('#irc3', 'async') future.set_result(ctx) bot = self.callFTU(loop=loop) e = irc3.utils.wraps_with_context(e, bot) bot.attach_events(irc3.event(irc3.rfc.PRIVMSG, e)) bot.dispatch(':g!g@g PRIVMSG #irc3 :async') loop.run_until_complete(future) assert future.result() is bot
def test_callable(self): loop = asyncio.new_event_loop() bot = self.callFTU(loop=loop) bot.include(__name__) plugin = bot.get_plugin(cron.Crons) results = [] f = asyncio.Future(loop=loop) def complete(future): results.append(future.result()) if len(results) == 2: f.set_result(results) for c in plugin: asyncio. async (c.next(), loop=loop).add_done_callback(complete) loop.run_until_complete(f) assert results == [bot, bot]
def test_callable(self): loop = asyncio.new_event_loop() bot = self.callFTU(loop=loop) bot.include(__name__) plugin = bot.get_plugin(cron.Crons) results = [] f = asyncio.Future(loop=loop) def complete(future): results.append(future.result()) if len(results) == 2: f.set_result(results) for c in plugin: asyncio.async(c.next(), loop=loop).add_done_callback(complete) loop.run_until_complete(f) assert results == [bot, bot]