コード例 #1
0
def test_run(
    cli_runner,
    mock_bot_class,
    mock_bot_class_instance,
    mock_setup_logging,
    mock_config_load,
):
    with open('config.toml', 'w') as f:
        f.write('')

    command = cli(mock_bot_class, './config.toml')
    cli_runner.invoke(command, [])

    mock_setup_logging.assert_called_once_with(
        {
            'bot_name': 'botty',
            'discord_api_key': 'API_KEY',
            'logging': {
                'log_file': 'botty.log',
                'log_to_console': False,
                'log_level': 'info',
            },
        }
    )
    mock_config_load.assert_called_once()
    mock_config_load.call_args[0][0].endswith('/config.toml')
    mock_bot_class.assert_called()
    mock_bot_class_instance.run_with_config.assert_called()
コード例 #2
0
def test_run_config(cli_runner, mock_bot_class, mock_config_load):
    with open('config.toml', 'w') as f:
        f.write('')

    with open('config-test.toml', 'w') as f:
        f.write('')

    command = cli(mock_bot_class, './config.toml')
    cli_runner.invoke(command, ['--config=config-test.toml'])

    mock_config_load.call_args[0][0].endswith('/config-test.toml')
コード例 #3
0
def test_run_config_exception(
    cli_runner, mock_bot_class, mock_config_load, mock_setup_logging
):
    with open('config.toml', 'w') as f:
        f.write('')

    mock_config_load.side_effect = ConfigException('No section and stuff')
    command = cli(mock_bot_class, './config.toml')
    result = cli_runner.invoke(command, [])
    assert result.exit_code == 2
    assert 'No section and stuff' in result.output
    mock_setup_logging.assert_not_called()
コード例 #4
0
def test_run_error_reading(
    cli_runner, mock_bot_class, mock_config_load, mock_setup_logging
):
    with open('config.toml', 'w') as f:
        f.write('')

    mock_config_load.side_effect = OSError()
    command = cli(mock_bot_class, './config.toml')
    result = cli_runner.invoke(command, [])
    assert result.exit_code == 2
    assert 'Error reading configuration file: ' in result.output
    mock_setup_logging.assert_not_called()
コード例 #5
0
def test_run_logging_config(cli_runner, mock_bot_class, mock_setup_logging):
    with open('config.toml', 'w') as f:
        f.write('')

    command = cli(mock_bot_class, './config.toml')
    cli_runner.invoke(command, [])

    mock_setup_logging.assert_called_once_with(
        {
            'bot_name': 'botty',
            'discord_api_key': 'API_KEY',
            'logging': {
                'log_file': 'botty.log',
                'log_to_console': True,
                'log_level': 'warning',
            },
        }
    )
コード例 #6
0
def main() -> None:
    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
    runner = cli(Bothanasius, './config.toml')
    runner()
コード例 #7
0
ファイル: run.py プロジェクト: bryanforbes/Erasmus
def main() -> None:
    uvloop.install()
    runner = cli(Erasmus, './config.toml', handler_cls=WatchedFileHandler)
    runner()
コード例 #8
0
#!/usr/bin/env python

import asyncio
import uvloop

from botus_receptus import cli
from bothanasius import Bothanasius

asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

if __name__ == '__main__':
    runner = cli(Bothanasius, './config.ini')
    runner()
コード例 #9
0
ファイル: krazon-bot.py プロジェクト: bryanforbes/Krazon
#!/usr/bin/env python

import asyncio
import uvloop

from botus_receptus import cli
from krazon import Krazon

asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

if __name__ == '__main__':
    runner = cli(Krazon, './config.ini')
    runner()
コード例 #10
0
def test_run_error_no_config(cli_runner, mock_bot_class, mock_setup_logging):
    command = cli(mock_bot_class, './config.toml')
    result = cli_runner.invoke(command, [])
    assert result.exit_code == 2
    mock_setup_logging.assert_not_called()
コード例 #11
0
ファイル: run.py プロジェクト: Hypirae/Erasmus
def main() -> None:
    uvloop.install()
    runner = cli(Erasmus, './config.toml')
    runner()