コード例 #1
0
    def test_unknown_commands(self):
        # test command server can properly handle 1 or multiple commands
        def default_process(args, sender):
            ok_(getattr(args, sender.code) is True)
            default_process.called += 1

        lap = LinotArgParser('testcmd', self.parser, default_process)
        lap.add_argument('-a', action='store_true')
        lap.add_argument('-b', action='store_true')
        lap.add_argument('-c', action='store_true')

        # Test 1 unknown command, command server respose to user
        sender_a = CommandSubmitter('test', 'a')
        fake_cmd = [
            (sender_a, 'some_unknown_words'),
        ]
        interfaces.get('test').reset()
        interfaces.get('test').add_command_list(fake_cmd)
        command_server.start(self.parser, ['test'])
        default_process.called = 0
        threading.Event().wait(.5)
        command_server.stop()
        ok_(default_process.called == 0)
        ok_('Unknown' in ' '.join(interfaces.get('test').msg_queue[sender_a.code]))

        # Test multiple unknown commands
        sender_a = CommandSubmitter('test', 'a')
        sender_u = CommandSubmitter('test', 'u')
        fake_cmd = [
            (sender_u, 'some_unknown_cmds'),
            (sender_a, 'testcmd -a'),
            (sender_u, 'some_unknown_cmds'),
        ]
        interfaces.get('test').reset()
        interfaces.get('test').add_command_list(fake_cmd)
        command_server.start(self.parser, ['test'])
        default_process.called = 0
        threading.Event().wait(.5)
        command_server.stop()
        unknown_response = ' '.join(interfaces.get('test').msg_queue[sender_u.code])
        ok_(unknown_response.count('Unknown') == 2)
        ok_(default_process.called == 1)
コード例 #2
0
    def test_cmd_process(self):
        # test command server can properly handle 1 or multiple commands
        def default_process(args, sender):
            ok_(getattr(args, sender.code) is True)
            default_process.called += 1

        lap = LinotArgParser('testcmd', self.parser, default_process)
        lap.add_argument('-a', action='store_true')
        lap.add_argument('-b', action='store_true')
        lap.add_argument('-c', action='store_true')

        # Test 1 cmd return by polling_command
        # command = [(sender, cmd string), ...]
        sender = CommandSubmitter('test', 'a')
        fake_cmd = [(sender, 'testcmd -a')]
        interfaces.get('test').add_command_list(fake_cmd)
        default_process.called = 0
        command_server.start(self.parser, ['test'])
        threading.Event().wait(.5)
        command_server.stop()
        ok_(default_process.called == 1)

        # Test 3 cmds return by polling_command
        # command = [(sender, cmd string), ...]
        sender_a = CommandSubmitter('test', 'a')
        sender_b = CommandSubmitter('test', 'b')
        sender_c = CommandSubmitter('test', 'c')
        fake_cmd = [
            (sender_a, 'testcmd -a'),
            (sender_b, 'testcmd -b'),
            (sender_c, 'testcmd -c'),
        ]
        interfaces.get('test').add_command_list(fake_cmd)
        command_server.start(self.parser, ['test'])
        default_process.called = 0
        threading.Event().wait(.5)
        command_server.stop()
        ok_(default_process.called == 3)
コード例 #3
0
    def test_direct_command(self):
        def default_process(args, sender):
            ok_(False)  # should not reach here

        lap = LinotArgParser('testcmd', self.parser, default_process)

        def cmd_checker(match_list, cmd, sender):
            ok_('somechannel' in match_list)
            ok_(len(match_list) == 1)
            ok_(cmd == 'www.twitch.tv/somechannel')
            cmd_checker.runned = True
        lap.add_direct_command(cmd_checker, 'twitch\.tv/(\w+)[\s\t,]*', re.IGNORECASE)
        cmd_checker.runned = False

        sender = CommandSubmitter('test', 'sender')
        fake_cmd = [
            (sender, 'www.twitch.tv/somechannel')
        ]
        interfaces.get('test').add_command_list(fake_cmd)
        command_server.start(self.parser, ['test'])
        threading.Event().wait(.5)
        command_server.stop()
        ok_(cmd_checker.runned)