Пример #1
0
 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']
Пример #2
0
 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']
Пример #3
0
 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()
Пример #4
0
 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()
Пример #5
0
    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
Пример #6
0
    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
Пример #7
0
    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]
Пример #8
0
    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]