Exemplo n.º 1
0
def test_run_setup(get_module_names, is_module_enabled, sys, importlib):
    get_module_names.return_value = ['chii.a', 'chii.b']
    is_module_enabled.side_effect = [True, True]
    chii_b = Mock()
    sys.modules = {'chii.a': None, 'chii.b': chii_b}

    load_commands(123, run_setup=True)
    assert chii_b.setup.called_with(123)
Exemplo n.º 2
0
def test_load_commands(get_module_names, is_module_enabled, sys, importlib):
    get_module_names.return_value = ['chii.a', 'chii.b', 'chii.c', 'chii.d']
    is_module_enabled.side_effect = [True, True, False, False]
    sys.modules = {'chii.b': 456, 'chii.d': Mock()}

    load_commands(123, run_setup=False)
    assert 'chii.d' not in sys.modules
    importlib.reload.assert_called_with(456)
    importlib.import_module.assert_called_with('chii.a')
Exemplo n.º 3
0
def test_load_commands(get_module_names, is_module_enabled, sys, importlib):
    get_module_names.return_value = ["chii.a", "chii.b", "chii.c", "chii.d"]
    is_module_enabled.side_effect = [True, True, False, False]
    sys.modules = {"chii.b": 456, "chii.d": Mock()}

    load_commands(123, run_setup=False)
    assert "chii.d" not in sys.modules
    importlib.reload.assert_called_with(456)
    importlib.import_module.assert_called_with("chii.a")
Exemplo n.º 4
0
async def call(message):
    """Hot reload the bot's config and modules."""
    try:
        config.reload()
    except Exception as e:  # noqa: E203
        logger.error(f'Error reloading config: {e}')
        raise BotError('Couldn\'t reload config.')

    try:
        load_commands(message.bot, run_setup=False)
    except Exception as e:  # noqa: E203
        logger.error(f'Error reloading modules: {e}')
        raise BotError('Couldn\'t reload modules.')

    return 'Commands reloaded.'
Exemplo n.º 5
0
    def start(self):
        load_commands(self)
        if hasattr(self, 'web_application'):
            self.webserver = self._start_webserver()

        self.connect()