def test_clean_callable_default(tmpconfig, func):
    loader.clean_callable(func, tmpconfig)

    # Default values
    assert hasattr(func, 'unblockable')
    assert func.unblockable is False
    assert hasattr(func, 'priority')
    assert func.priority == 'medium'
    assert hasattr(func, 'thread')
    assert func.thread is True
    assert hasattr(func, 'rate')
    assert func.rate == 0
    assert hasattr(func, 'channel_rate')
    assert func.rate == 0
    assert hasattr(func, 'global_rate')
    assert func.global_rate == 0
    assert hasattr(func, 'event')
    assert func.event == ['PRIVMSG']

    # Not added by default
    assert not hasattr(func, 'rule')
    assert not hasattr(func, 'commands')
    assert not hasattr(func, 'nickname_commands')
    assert not hasattr(func, 'action_commands')
    assert not hasattr(func, 'intents')
Exemple #2
0
def test_clean_callable_rule(tmpconfig, func):
    setattr(func, 'rule', [r'abc'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'rule')
    assert len(func.rule) == 1

    # Test the regex is compiled properly
    regex = re.compile(func.rule[0])
    assert regex.match('abc')
    assert regex.match('abcd')
    assert not regex.match('efg')

    # Default values
    assert hasattr(func, 'unblockable')
    assert func.unblockable is False
    assert hasattr(func, 'priority')
    assert func.priority == 'medium'
    assert hasattr(func, 'thread')
    assert func.thread is True
    assert hasattr(func, 'user_rate')
    assert func.user_rate == 0
    assert hasattr(func, 'channel_rate')
    assert func.channel_rate == 0
    assert hasattr(func, 'global_rate')
    assert func.global_rate == 0
    assert hasattr(func, 'user_rate_message')
    assert func.user_rate_message is None
    assert hasattr(func, 'channel_rate_message')
    assert func.channel_rate_message is None
    assert hasattr(func, 'global_rate_message')
    assert func.global_rate_message is None
    assert hasattr(func, 'default_rate_message')
    assert func.default_rate_message is None
    assert hasattr(func, 'echo')
    assert func.echo is False
    assert hasattr(func, 'allow_bots')
    assert func.allow_bots is False
    assert hasattr(func, 'output_prefix')
    assert func.output_prefix == ''

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert len(func.rule) == 1
    assert regex not in func.rule
    assert r'abc' in func.rule

    assert func.unblockable is False
    assert func.priority == 'medium'
    assert func.thread is True
    assert func.user_rate == 0
    assert func.channel_rate == 0
    assert func.global_rate == 0
    assert func.user_rate_message is None
    assert func.channel_rate_message is None
    assert func.global_rate_message is None
    assert func.default_rate_message is None
    assert func.echo is False
    assert func.allow_bots is False
    assert func.output_prefix == ''
Exemple #3
0
def test_clean_callable_event(tmpconfig, func):
    setattr(func, 'event', ['low', 'UP', 'MiXeD'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['LOW', 'UP', 'MIXED']

    # Default values
    assert hasattr(func, 'unblockable')
    assert func.unblockable is False
    assert hasattr(func, 'priority')
    assert func.priority == 'medium'
    assert hasattr(func, 'thread')
    assert func.thread is True
    assert hasattr(func, 'rate')
    assert func.rate == 0
    assert hasattr(func, 'channel_rate')
    assert func.channel_rate == 0
    assert hasattr(func, 'global_rate')
    assert func.global_rate == 0

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert func.event == ['LOW', 'UP', 'MIXED']

    assert func.unblockable is False
    assert func.priority == 'medium'
    assert func.thread is True
    assert func.rate == 0
    assert func.channel_rate == 0
    assert func.global_rate == 0
Exemple #4
0
def perform_who(bot, trigger, nick=None, success=None, fail=None, end=None):
    @module.rule('.*')
    @module.priority('high')
    @module.event('354')
    def who_recv(b, t):
        global flag
        flag = True
        if success:
            success(b, t)


    @module.rule('.*')
    @module.priority('low')
    @module.event('315')
    def who_end(b, t):
        global flag
        if fail and not flag:
            fail(b, t)
        if end:
            end(b, t)
        flag = False
        bot.unregister(who_recv)
        bot.unregister(who_end)


    if not nick:
        nick = trigger.nick
    loader.clean_callable(who_recv, bot.config)
    loader.clean_callable(who_end, bot.config)
    meta = ([who_recv, who_end],[],[])
    bot.register(*meta)
    bot.write(['WHO', nick, '%na'])
Exemple #5
0
def test_clean_callable_nickname_command(tmpconfig, func):
    setattr(func, 'nickname_commands', ['hello!'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'nickname_commands')
    assert len(func.nickname_commands) == 1
    assert func.nickname_commands == ['hello!']
    assert not hasattr(func, 'rule')

    # Default values
    assert hasattr(func, 'unblockable')
    assert func.unblockable is False
    assert hasattr(func, 'priority')
    assert func.priority == 'medium'
    assert hasattr(func, 'thread')
    assert func.thread is True
    assert hasattr(func, 'rate')
    assert func.rate == 0
    assert hasattr(func, 'channel_rate')
    assert func.channel_rate == 0
    assert hasattr(func, 'global_rate')
    assert func.global_rate == 0

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert not hasattr(func, 'rule')
    assert func.unblockable is False
    assert func.priority == 'medium'
    assert func.thread is True
    assert func.rate == 0
    assert func.channel_rate == 0
    assert func.global_rate == 0
Exemple #6
0
def test_clean_callable_url(tmpconfig, func):
    setattr(func, 'url_regex', [re.compile('.*')])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'url_regex')
    assert len(func.url_regex) == 1

    # Don't test the regex; that's handled in a different module
    # Default values
    assert hasattr(func, 'unblockable')
    assert func.unblockable is False
    assert hasattr(func, 'thread')
    assert func.thread is True
    assert hasattr(func, 'rate')
    assert func.rate == 0
    assert hasattr(func, 'channel_rate')
    assert func.channel_rate == 0
    assert hasattr(func, 'global_rate')
    assert func.global_rate == 0

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert len(func.url_regex) == 1
    assert func.unblockable is False
    assert func.thread is True
    assert func.rate == 0
    assert func.channel_rate == 0
    assert func.global_rate == 0
Exemple #7
0
def test_clean_callable_default(tmpconfig, func):
    loader.clean_callable(func, tmpconfig)

    # Default values
    assert hasattr(func, 'thread')
    assert func.thread is True

    # Not added by default
    assert not hasattr(func, 'unblockable')
    assert not hasattr(func, 'priority')
    assert not hasattr(func, 'rate')
    assert not hasattr(func, 'channel_rate')
    assert not hasattr(func, 'global_rate')
    assert not hasattr(func, 'echo')
    assert not hasattr(func, 'allow_bots')
    assert not hasattr(func, 'output_prefix')
    assert not hasattr(func, 'event')
    assert not hasattr(func, 'rule')
    assert not hasattr(func, 'find_rules')
    assert not hasattr(func, 'search_rules')
    assert not hasattr(func, 'rule_lazy_loaders')
    assert not hasattr(func, 'find_rules_lazy_loaders')
    assert not hasattr(func, 'search_rules_lazy_loaders')
    assert not hasattr(func, 'commands')
    assert not hasattr(func, 'nickname_commands')
    assert not hasattr(func, 'action_commands')
    assert not hasattr(func, 'ctcp')
Exemple #8
0
 def register_timeout_jobs(self, handlers):
     """Register the timeout handlers for the timeout scheduler."""
     for handler in handlers:
         loader.clean_callable(handler, self.bot.settings)
         job = jobs.Job.from_callable(self.bot.settings, handler)
         self.timeout_scheduler.register(job)
         LOGGER.debug('Timeout Job registered: %s', str(job))
Exemple #9
0
def test_clean_callable_command(tmpconfig, func):
    setattr(func, 'commands', ['test'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'commands')
    assert func.commands == ['test']

    # Default values
    assert hasattr(func, 'unblockable')
    assert func.unblockable is False
    assert hasattr(func, 'priority')
    assert func.priority == 'medium'
    assert hasattr(func, 'thread')
    assert func.thread is True
    assert hasattr(func, 'user_rate')
    assert func.user_rate == 0
    assert hasattr(func, 'channel_rate')
    assert func.channel_rate == 0
    assert hasattr(func, 'global_rate')
    assert func.global_rate == 0
    assert hasattr(func, 'user_rate_message')
    assert func.user_rate_message is None
    assert hasattr(func, 'channel_rate_message')
    assert func.channel_rate_message is None
    assert hasattr(func, 'global_rate_message')
    assert func.global_rate_message is None
    assert hasattr(func, 'default_rate_message')
    assert func.default_rate_message is None
    assert hasattr(func, 'echo')
    assert func.echo is False
    assert hasattr(func, 'allow_bots')
    assert func.allow_bots is False
    assert hasattr(func, 'output_prefix')
    assert func.output_prefix == ''
    assert hasattr(func, 'event')
    assert func.event == ['PRIVMSG']
    assert not hasattr(func, 'rule')

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert func.commands == ['test']

    assert func.unblockable is False
    assert func.priority == 'medium'
    assert func.thread is True
    assert func.user_rate == 0
    assert func.channel_rate == 0
    assert func.global_rate == 0
    assert func.user_rate_message is None
    assert func.channel_rate_message is None
    assert func.global_rate_message is None
    assert func.default_rate_message is None
    assert func.echo is False
    assert func.allow_bots is False
    assert func.output_prefix == ''
    assert func.event == ['PRIVMSG']
Exemple #10
0
def test_clean_callable_event(tmpconfig, func):
    setattr(func, 'event', ['low', 'UP', 'MiXeD'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['LOW', 'UP', 'MIXED']

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert func.event == ['LOW', 'UP', 'MIXED']
Exemple #11
0
def test_clean_callable_event_string(tmpconfig, func):
    setattr(func, 'event', 'some')
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['SOME']

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert func.event == ['SOME']
Exemple #12
0
def test_clean_callable_event_string(tmpconfig, func):
    setattr(func, 'event', 'some')
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['SOME']

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert func.event == ['SOME']
def test_clean_callable_event(tmpconfig, func):
    setattr(func, 'event', ['low', 'UP', 'MiXeD'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['LOW', 'UP', 'MIXED']

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert func.event == ['LOW', 'UP', 'MIXED']
Exemple #14
0
def test_clean_callable_rule_nickname(tmpconfig, func):
    """Assert ``$nick`` in a rule will match ``TestBot``."""
    setattr(func, 'rule', [r'$nickname\s+hello'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'rule')
    assert len(func.rule) == 1

    # Test the regex is compiled properly
    regex = func.rule[0]
    assert regex.match('TestBot hello')
    assert not regex.match('TestBot not hello')
Exemple #15
0
def test_clean_callable_events_basetring(tmpconfig, func):
    setattr(func, 'event', 'topic')
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['TOPIC']

    setattr(func, 'event', 'JOIN')
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['JOIN']
Exemple #16
0
def test_clean_callable_rule_string(tmpconfig, func):
    setattr(func, 'rule', r'abc')
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'rule')
    assert len(func.rule) == 1

    # Test the regex is compiled properly
    regex = func.rule[0]
    assert regex.match('abc')
    assert regex.match('abcd')
    assert not regex.match('efg')
Exemple #17
0
def test_clean_callable_rule_nickname(tmpconfig, func):
    """Assert ``$nick`` in a rule will match ``TestBot``."""
    setattr(func, 'rule', [r'$nickname\s+hello'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'rule')
    assert len(func.rule) == 1

    # Test the regex is compiled properly
    regex = func.rule[0]
    assert regex.match('TestBot hello')
    assert not regex.match('TestBot not hello')
Exemple #18
0
def test_clean_callable_events_basetring(tmpconfig, func):
    setattr(func, 'event', 'topic')
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['TOPIC']

    setattr(func, 'event', 'JOIN')
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['JOIN']
Exemple #19
0
def test_clean_callable_rule_string(tmpconfig, func):
    setattr(func, 'rule', r'abc')
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'rule')
    assert len(func.rule) == 1

    # Test the regex is compiled properly
    regex = func.rule[0]
    assert regex.match('abc')
    assert regex.match('abcd')
    assert not regex.match('efg')
Exemple #20
0
def test_clean_callable_event(tmpconfig, func):
    setattr(func, 'event', ['low', 'UP', 'MiXeD'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['LOW', 'UP', 'MIXED']

    # Default values
    assert hasattr(func, 'unblockable')
    assert func.unblockable is False
    assert hasattr(func, 'priority')
    assert func.priority == 'medium'
    assert hasattr(func, 'thread')
    assert func.thread is True
    assert hasattr(func, 'user_rate')
    assert func.user_rate == 0
    assert hasattr(func, 'channel_rate')
    assert func.channel_rate == 0
    assert hasattr(func, 'global_rate')
    assert func.global_rate == 0
    assert hasattr(func, 'user_rate_message')
    assert func.user_rate_message is None
    assert hasattr(func, 'channel_rate_message')
    assert func.channel_rate_message is None
    assert hasattr(func, 'global_rate_message')
    assert func.global_rate_message is None
    assert hasattr(func, 'default_rate_message')
    assert func.default_rate_message is None
    assert hasattr(func, 'echo')
    assert func.echo is False
    assert hasattr(func, 'allow_bots')
    assert func.allow_bots is False
    assert hasattr(func, 'output_prefix')
    assert func.output_prefix == ''

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert func.event == ['LOW', 'UP', 'MIXED']

    assert func.unblockable is False
    assert func.priority == 'medium'
    assert func.thread is True
    assert func.user_rate == 0
    assert func.channel_rate == 0
    assert func.global_rate == 0
    assert func.user_rate_message is None
    assert func.channel_rate_message is None
    assert func.global_rate_message is None
    assert func.default_rate_message is None
    assert func.echo is False
    assert func.allow_bots is False
    assert func.output_prefix == ''
Exemple #21
0
def test_clean_callable_search_rules(tmpconfig, func):
    setattr(func, 'search_rules', [r'abc'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'search_rules')
    assert len(func.search_rules) == 1
    assert not hasattr(func, 'rule')

    # Test the regex is compiled properly
    regex = re.compile(func.search_rules[0])
    assert regex.search('abc')
    assert regex.search('xyzabc')
    assert regex.search('abcd')
    assert not regex.search('adbc')

    # Default values
    assert hasattr(func, 'unblockable')
    assert func.unblockable is False
    assert hasattr(func, 'priority')
    assert func.priority == 'medium'
    assert hasattr(func, 'thread')
    assert func.thread is True
    assert hasattr(func, 'rate')
    assert func.rate == 0
    assert hasattr(func, 'channel_rate')
    assert func.channel_rate == 0
    assert hasattr(func, 'global_rate')
    assert func.global_rate == 0
    assert hasattr(func, 'echo')
    assert func.echo is False
    assert hasattr(func, 'allow_bots')
    assert func.allow_bots is False
    assert hasattr(func, 'output_prefix')
    assert func.output_prefix == ''

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert hasattr(func, 'search_rules')
    assert len(func.search_rules) == 1
    assert regex not in func.search_rules
    assert func.search_rules[0] == r'abc'
    assert not hasattr(func, 'rule')

    assert func.unblockable is False
    assert func.priority == 'medium'
    assert func.thread is True
    assert func.rate == 0
    assert func.channel_rate == 0
    assert func.global_rate == 0
    assert func.echo is False
    assert func.allow_bots is False
    assert func.output_prefix == ''
Exemple #22
0
def test_clean_callable_example_not_set(tmpconfig, func):
    module.commands('test')(func)

    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, '_docs')
    assert len(func._docs) == 1
    assert 'test' in func._docs

    docs = func._docs['test']
    assert len(docs) == 2
    assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert docs[1] == []
Exemple #23
0
def test_clean_callable_example_not_set(tmpconfig, func):
    module.commands('test')(func)

    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, '_docs')
    assert len(func._docs) == 1
    assert 'test' in func._docs

    docs = func._docs['test']
    assert len(docs) == 2
    assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert docs[1] == []
Exemple #24
0
def test_clean_callable_action_command(tmpconfig, func):
    setattr(func, 'action_commands', ['bots'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'action_commands')
    assert len(func.action_commands) == 1
    assert func.action_commands == ['bots']
    assert not hasattr(func, 'rule')

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert not hasattr(func, 'rule')
    assert func.action_commands == ['bots']
Exemple #25
0
def test_clean_callable_example_user_help(tmpconfig, func):
    module.commands('test')(func)
    module.example('.test hello', user_help=True)(func)

    loader.clean_callable(func, tmpconfig)

    assert len(func._docs) == 1
    assert 'test' in func._docs

    docs = func._docs['test']
    assert len(docs) == 2
    assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert docs[1] == ['.test hello']
Exemple #26
0
def test_clean_callable_example_user_help(tmpconfig, func):
    module.commands('test')(func)
    module.example('.test hello', user_help=True)(func)

    loader.clean_callable(func, tmpconfig)

    assert len(func._docs) == 1
    assert 'test' in func._docs

    docs = func._docs['test']
    assert len(docs) == 2
    assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert docs[1] == ['.test hello']
Exemple #27
0
def setup(bot):
    bot.memory['join_events_queue'] = collections.deque()

    # Manage JOIN flood protection
    if bot.settings.core.throttle_join:
        wait_interval = max(bot.settings.core.throttle_wait, 1)

        @module.interval(wait_interval)
        def processing_job(bot):
            _join_event_processing(bot)

        loader.clean_callable(processing_job, bot.settings)
        bot.scheduler.add_job(jobs.Job(wait_interval, processing_job))
Exemple #28
0
def test_clean_callable_example_nickname(tmpconfig, func):
    module.commands('test')(func)
    module.example('$nickname: hello')(func)

    loader.clean_callable(func, tmpconfig)

    assert len(func._docs) == 1
    assert 'test' in func._docs

    docs = func._docs['test']
    assert len(docs) == 2
    assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert docs[1] == 'TestBot: hello'
Exemple #29
0
def test_clean_callable_example_nickname(tmpconfig, func):
    module.commands('test')(func)
    module.example('$nickname: hello')(func)

    loader.clean_callable(func, tmpconfig)

    assert len(func._docs) == 1
    assert 'test' in func._docs

    docs = func._docs['test']
    assert len(docs) == 2
    assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert docs[1] == 'TestBot: hello'
Exemple #30
0
def test_clean_callable_example_default_prefix(tmpconfig, func):
    module.commands('test')(func)
    module.example('.test hello')(func)

    tmpconfig.core.help_prefix = '!'
    loader.clean_callable(func, tmpconfig)

    assert len(func._docs) == 1
    assert 'test' in func._docs

    docs = func._docs['test']
    assert len(docs) == 2
    assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert docs[1] == '!test hello'
Exemple #31
0
def test_clean_callable_example_first_only(tmpconfig, func):
    module.commands('test')(func)
    module.example('.test hello')(func)
    module.example('.test bonjour')(func)

    loader.clean_callable(func, tmpconfig)

    assert len(func._docs) == 1
    assert 'test' in func._docs

    docs = func._docs['test']
    assert len(docs) == 2
    assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert docs[1] == '.test hello'
Exemple #32
0
def test_clean_callable_example_nickname_custom_prefix(tmpconfig, func):
    plugin.commands('test')(func)
    plugin.example('$nickname: hello')(func)

    tmpconfig.core.help_prefix = '!'
    loader.clean_callable(func, tmpconfig)

    assert len(func._docs) == 1
    assert 'test' in func._docs

    docs = func._docs['test']
    assert len(docs) == 2
    assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert docs[1] == ['TestBot: hello']
Exemple #33
0
def test_clean_callable_intents(tmpconfig, func):
    setattr(func, 'intents', [r'abc'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'intents')
    assert len(func.intents) == 1

    # Test the regex is compiled properly
    regex = func.intents[0]
    assert regex.match('abc')
    assert regex.match('abcd')
    assert regex.match('ABC')
    assert regex.match('AbCdE')
    assert not regex.match('efg')
Exemple #34
0
def test_clean_callable_example_default_prefix(tmpconfig, func):
    module.commands('test')(func)
    module.example('.test hello')(func)

    tmpconfig.core.help_prefix = '!'
    loader.clean_callable(func, tmpconfig)

    assert len(func._docs) == 1
    assert 'test' in func._docs

    docs = func._docs['test']
    assert len(docs) == 2
    assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert docs[1] == '!test hello'
Exemple #35
0
def test_clean_callable_example_first_only(tmpconfig, func):
    module.commands('test')(func)
    module.example('.test hello')(func)
    module.example('.test bonjour')(func)

    loader.clean_callable(func, tmpconfig)

    assert len(func._docs) == 1
    assert 'test' in func._docs

    docs = func._docs['test']
    assert len(docs) == 2
    assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert docs[1] == '.test hello'
Exemple #36
0
def test_clean_callable_intents(tmpconfig, func):
    setattr(func, 'intents', [r'abc'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'intents')
    assert len(func.intents) == 1

    # Test the regex is compiled properly
    regex = func.intents[0]
    assert regex.match('abc')
    assert regex.match('abcd')
    assert regex.match('ABC')
    assert regex.match('AbCdE')
    assert not regex.match('efg')
Exemple #37
0
def test_clean_callable_rule_string(tmpconfig, func):
    setattr(func, 'rule', r'abc')
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'rule')
    assert len(func.rule) == 1

    # Test the regex is compiled properly
    assert func.rule[0] == r'abc'

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert len(func.rule) == 1
    assert func.rule[0] == r'abc'
Exemple #38
0
def test_clean_callable_example(tmpconfig, func):
    plugin.commands('test')(func)
    plugin.example('.test hello')(func)

    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, '_docs')
    assert len(func._docs) == 1
    assert 'test' in func._docs

    docs = func._docs['test']
    assert len(docs) == 2
    assert docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert docs[1] == ['.test hello']
Exemple #39
0
def test_clean_callable_ctcp(tmpconfig, func):
    setattr(func, 'ctcp', [r'abc'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'ctcp')
    assert len(func.ctcp) == 1

    # Test the regex is compiled properly
    regex = func.ctcp[0]
    assert regex.match('abc')
    assert regex.match('abcd')
    assert regex.match('ABC')
    assert regex.match('AbCdE')
    assert not regex.match('efg')

    # Default values
    assert hasattr(func, 'unblockable')
    assert func.unblockable is False
    assert hasattr(func, 'priority')
    assert func.priority == 'medium'
    assert hasattr(func, 'thread')
    assert func.thread is True
    assert hasattr(func, 'rate')
    assert func.rate == 0
    assert hasattr(func, 'channel_rate')
    assert func.channel_rate == 0
    assert hasattr(func, 'global_rate')
    assert func.global_rate == 0
    assert hasattr(func, 'echo')
    assert func.echo is False
    assert hasattr(func, 'allow_bots')
    assert func.allow_bots is False
    assert hasattr(func, 'output_prefix')
    assert func.output_prefix == ''

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert len(func.ctcp) == 1
    assert regex in func.ctcp

    assert func.unblockable is False
    assert func.priority == 'medium'
    assert func.thread is True
    assert func.rate == 0
    assert func.channel_rate == 0
    assert func.global_rate == 0
    assert func.echo is False
    assert func.allow_bots is False
    assert func.output_prefix == ''
Exemple #40
0
def test_clean_callable_url(tmpconfig, func):
    setattr(func, 'url_regex', [re.compile('.*')])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'url_regex')
    assert len(func.url_regex) == 1

    # Don't test the regex; that's handled in a different module
    # Default values
    assert hasattr(func, 'unblockable')
    assert func.unblockable is False
    assert hasattr(func, 'thread')
    assert func.thread is True
    assert hasattr(func, 'user_rate')
    assert func.user_rate == 0
    assert hasattr(func, 'channel_rate')
    assert func.channel_rate == 0
    assert hasattr(func, 'global_rate')
    assert func.global_rate == 0
    assert hasattr(func, 'user_rate_message')
    assert func.user_rate_message is None
    assert hasattr(func, 'channel_rate_message')
    assert func.channel_rate_message is None
    assert hasattr(func, 'global_rate_message')
    assert func.global_rate_message is None
    assert hasattr(func, 'default_rate_message')
    assert func.default_rate_message is None
    assert hasattr(func, 'echo')
    assert func.echo is False
    assert hasattr(func, 'allow_bots')
    assert func.allow_bots is False
    assert hasattr(func, 'output_prefix')
    assert func.output_prefix == ''

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert len(func.url_regex) == 1
    assert func.unblockable is False
    assert func.thread is True
    assert func.user_rate == 0
    assert func.channel_rate == 0
    assert func.global_rate == 0
    assert func.user_rate_message is None
    assert func.channel_rate_message is None
    assert func.global_rate_message is None
    assert func.default_rate_message is None
    assert func.echo is False
    assert func.allow_bots is False
    assert func.output_prefix == ''
Exemple #41
0
def test_clean_callable_nickname_command(tmpconfig, func):
    setattr(func, 'nickname_commands', ['hello!'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'nickname_commands')
    assert len(func.nickname_commands) == 1
    assert func.nickname_commands == ['hello!']
    assert hasattr(func, 'rule')
    assert len(func.rule) == 1

    regex = func.rule[0]
    assert regex.match('TestBot hello!')
    assert regex.match('TestBot, hello!')
    assert regex.match('TestBot: hello!')
    assert not regex.match('TestBot not hello')
Exemple #42
0
def test_clean_callable_rule_nickname(tmpconfig, func):
    """Assert ``$nickname`` in a rule is not replaced (deprecated feature)."""
    setattr(func, 'rule', [r'$nickname\s+hello'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'rule')
    assert len(func.rule) == 1

    # Test the regex is not compiled
    assert func.rule[0] == r'$nickname\s+hello'

    # idempotency
    loader.clean_callable(func, tmpconfig)
    assert len(func.rule) == 1
    assert func.rule[0] == r'$nickname\s+hello'
Exemple #43
0
def test_clean_callable_nickname_command(tmpconfig, func):
    setattr(func, 'nickname_commands', ['hello!'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'nickname_commands')
    assert len(func.nickname_commands) == 1
    assert func.nickname_commands == ['hello!']
    assert hasattr(func, 'rule')
    assert len(func.rule) == 1

    regex = func.rule[0]
    assert regex.match('TestBot hello!')
    assert regex.match('TestBot, hello!')
    assert regex.match('TestBot: hello!')
    assert not regex.match('TestBot not hello')
Exemple #44
0
def test_clean_callable_example_multi_commands(tmpconfig, func):
    module.commands('test')(func)
    module.commands('unit')(func)
    module.example('.test hello')(func)

    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, '_docs')
    assert len(func._docs) == 2
    assert 'test' in func._docs
    assert 'unit' in func._docs

    test_docs = func._docs['test']
    unit_docs = func._docs['unit']
    assert len(test_docs) == 2
    assert test_docs == unit_docs

    assert test_docs[0] == inspect.cleandoc(func.__doc__).splitlines()
    assert test_docs[1] == '.test hello'
Exemple #45
0
def test_clean_callable_default(tmpconfig, func):
    loader.clean_callable(func, tmpconfig)

    # Default values
    assert hasattr(func, 'unblockable')
    assert func.unblockable is False
    assert hasattr(func, 'priority')
    assert func.priority == 'medium'
    assert hasattr(func, 'thread')
    assert func.thread is True
    assert hasattr(func, 'rate')
    assert func.rate == 0
    assert hasattr(func, 'channel_rate')
    assert func.rate == 0
    assert hasattr(func, 'global_rate')
    assert func.global_rate == 0
    assert hasattr(func, 'event')
    assert func.event == ['PRIVMSG']

    # Not added by default
    assert not hasattr(func, 'rule')
    assert not hasattr(func, 'commands')
    assert not hasattr(func, 'intents')
Exemple #46
0
def test_clean_callable_events(tmpconfig, func):
    setattr(func, 'event', ['TOPIC'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['TOPIC']

    setattr(func, 'event', ['TOPIC', 'JOIN'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['TOPIC', 'JOIN']

    setattr(func, 'event', ['TOPIC', 'join', 'Nick'])
    loader.clean_callable(func, tmpconfig)

    assert hasattr(func, 'event')
    assert func.event == ['TOPIC', 'JOIN', 'NICK']