コード例 #1
0
    def setUp(self):
        self.disp = dispatcher.Dispatcher(bot)
        self.disp.init({})

        self.said = []
        bot.msg = lambda *a: self.said.append(a)

        class Helper(object):
            def f(self, *a):
                pass

            def g(self, *a):
                "foo"

            def h(self, *a):
                "bar"

            def i(self, *a):
                pass

        self.help1 = Helper()
        self.help2 = Helper()
        self.disp.new_plugin(self.help1, "channel")
        self.disp.new_plugin(self.help2, "chann2")
        self.generic_help = GENERIC_HELP
        self.nodocstring = NODOCSTRING
        self.severaldocs = SEVERALDOCS
コード例 #2
0
ファイル: test_dispatcher.py プロジェクト: rbistolfi/lalita
    def setUp(self):
        super(TestPluginI18n, self).setUp()
        self.disp = dispatcher.Dispatcher(self.bot)
        self.disp.init({})

        class Helper(Plugin):
            def init(self, *args):
                d = {'a message' : {'es' : 'un mensaje'},
                     'with args: %s' : {'es' : 'con args: %s'}
                    }
                self.register_translation(self, d)
            def simple(self, user, channel, *args):
                self.say(channel, 'a message')
                self.test(True)
            def withargs(self, user, channel, command, *args):
                self.say(channel, 'with args: %s', command)
                self.test(True)

        self.helper = Helper({'nickname':'helper', 'encoding':'fake'}, 'DEBUG')
        self.disp.config['channels'] = {'channel-es':{'language':'es'}}
        self.old_msg = self.bot.msg
        self.answer = []
        def g(towhere, msg, _):
            self.answer.append((towhere, msg.decode("utf8")))
        self.bot.msg = g
コード例 #3
0
ファイル: test_dispatcher.py プロジェクト: rbistolfi/lalita
    def test_problem_alert_executing(self):
        """A problem with the execution is reported to the ircmaster."""
        disp = dispatcher.Dispatcher(self.bot)
        recorder = []
        disp._msg = lambda *a: recorder.append(a)
        disp.init({'ircmaster':'ircmaster'})

        class Helper(object):
            """Plugin that says what we tell to say."""
            def f(self, *args):
                """Have a problem."""
                raise ValueError("problem!")

        helper = Helper()
        disp.new_plugin(helper, "#channel")
        disp.register(events.PUBLIC_MESSAGE, helper.f)

        d = defer.Deferred()
        d.addCallback(lambda _: disp.push(events.PUBLIC_MESSAGE,
                                          "usr", "#channel", "bu"))

        def check(_):
            """Check what's reported."""
            m = "Error calling the plugin 'lalita.core.tests."\
                "test_dispatcher.Helper': ValueError('problem!',)"
            self.assertEqual(recorder[0], ("ircmaster", m))

        d.addCallback(check)
        d.callback(True)
        return d
コード例 #4
0
ファイル: test_dispatcher.py プロジェクト: rbistolfi/lalita
    def test_problem_alert_message(self):
        """A problem with the message is reported to the ircmaster."""
        disp = dispatcher.Dispatcher(self.bot)
        recorder = []
        disp._msg = lambda *a: recorder.append(a)
        disp.init({'ircmaster':'ircmaster'})

        class Helper(object):
            """Plugin that says what we tell to say."""
            def f(self, *args):
                """Say something bad."""
                self.say("usr", "foo %d", "no int")

        helper = Helper()
        disp.new_plugin(helper, "#channel")
        disp.register(events.PUBLIC_MESSAGE, helper.f)

        d = defer.Deferred()
        d.addCallback(lambda _: disp.push(events.PUBLIC_MESSAGE,
                                          "usr", "#channel", "bu"))

        def check(_):
            """Check what's reported."""
            m = "Unable to format message! Msg: 'foo %d'  Args: ('no int',)"
            self.assertEqual(recorder[0], ("ircmaster", m))

        d.addCallback(check)
        d.callback(True)
        return d
コード例 #5
0
ファイル: test_dispatcher.py プロジェクト: rbistolfi/lalita
    def setUp(self):
        super(TestTooMuchTalk, self).setUp()
        self.disp = disp = dispatcher.Dispatcher(self.bot)

        # let's register what the dispatcher says that plugin said
        self.recorder = []
        disp._msg = lambda *a: self.recorder.append(a)
        disp.init({})
コード例 #6
0
    def setUp(self):
        self.disp = dispatcher.Dispatcher(bot)
        self.disp.init({})

        self.said = []
        bot.msg = lambda *a: self.said.append(a)

        self.helper = self.Helper()
        self.disp.new_plugin(self.helper, "channel")
        self.prefix_list = PREFIX_LIST
コード例 #7
0
ファイル: test_dispatcher.py プロジェクト: rbistolfi/lalita
    def setUp(self):
        super(TestEvents, self).setUp()
        self.disp = dispatcher.Dispatcher(self.bot)
        self.disp.init({})

        class Helper(object):
            def f(self, *args):
                return self.test(*args)
        self.helper = Helper()
        self.disp.new_plugin(self.helper, "channel")
コード例 #8
0
    def setUp(self):
        self.disp = dispatcher.Dispatcher(bot)
        self.disp.init({})

        self.said = []
        bot.msg = lambda *a: self.said.append(a)

        self.helper = self.Helper()
        self.disp.new_plugin(self.helper, "channel")
        self.generic_help = GENERIC_HELP
        self.nodocstring = NODOCSTRING
        self.severaldocs = SEVERALDOCS
        self.nosuchcmd = NOSUCHCMD
コード例 #9
0
ファイル: test_dispatcher.py プロジェクト: rbistolfi/lalita
    def setUp(self):
        super(TestSay, self).setUp()
        self._disp = disp = dispatcher.Dispatcher(self.bot)

        # let's register what the dispatcher says that plugin said
        self.recorder = []
        disp._msg = lambda *a: self.recorder.append(a)
        disp.init({})

        class Helper(object):
            '''Plugin that says what we tell to say.'''
            def f(self, *args):
                for what in self.what:
                    self.say(*what)

        self.helper = Helper()
        disp.new_plugin(self.helper, "#channel")
        disp.register(events.PUBLIC_MESSAGE, self.helper.f)
        self.deferred.addCallback(lambda _: disp.push(events.PUBLIC_MESSAGE,
                                                      "usr", "#channel", "bu"))
コード例 #10
0
ファイル: test_dispatcher.py プロジェクト: rbistolfi/lalita
    def setUp(self):
        super(TestFlowController, self).setUp()
        dispatcher.FLOW_TIMEOUT = 1
        self.disp = disp = dispatcher.Dispatcher(self.bot)

        # let's register what the dispatcher says that plugin said
        self.recorder = []
        disp._msg = lambda *a: self.recorder.append(a)
        disp.init({})

        class Helper(object):
            '''Plugin that says what we tell to say.'''
            def f(self, usr, chnl, txt):
                for to, msg in self.what:
                    if usr == to:
                        self.say(to, msg)

            def g(self, *a):
                '''nothing!'''

        self.helper = Helper()
        disp.new_plugin(self.helper, "#channel")
        disp.register(events.PUBLIC_MESSAGE, self.helper.f)
        disp.register(events.COMMAND, self.helper.g, ("void",))
コード例 #11
0
 def __init__(self, *more):
     self.dispatcher = dispatcher.Dispatcher(self)
     self._plugins = {}
     logger.info("We're in(ited)!")
コード例 #12
0
ファイル: test_dispatcher.py プロジェクト: rbistolfi/lalita
 def setUp(self):
     Base.setUp(self)
     self.disp = dispatcher.Dispatcher(self.bot)
     self.disp.init({})