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()
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')
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()
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()
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', }, } )
def main() -> None: asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) runner = cli(Bothanasius, './config.toml') runner()
def main() -> None: uvloop.install() runner = cli(Erasmus, './config.toml', handler_cls=WatchedFileHandler) runner()
#!/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()
#!/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()
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()
def main() -> None: uvloop.install() runner = cli(Erasmus, './config.toml') runner()