def test_load_no_bot_name(tmp_path): c = tmp_path / 'config.toml' c.write_text('''[bot] discord_api_key = "API_KEY" ''') with pytest.raises(config.ConfigException, match='"bot_name" not specified in the config file'): config.load(str(c))
def test_load_no_bot_section(tmp_path): c = tmp_path / 'config.toml' c.write_text('''[foo] bot_name = "botty" discord_api_key = "API_KEY" ''') with pytest.raises(config.ConfigException, match='"bot" section not in config file'): config.load(str(c))
def test_load_no_api_key(tmp_path): c = tmp_path / 'config.toml' c.write_text('''[bot] bot_name = "botty" ''') with pytest.raises( config.ConfigException, match='"discord_api_key" not specified in the config file', ): config.load(str(c))
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ bot_config = load(Path(__file__).resolve().parent.parent / 'config.toml') connectable = engine_from_config(config.get_section( config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool, url=bot_config['db_url']) def process_revision_directives(context, revision, directives): if config.cmd_opts.autogenerate: script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] with connectable.connect() as connection: context.configure( connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, ) with context.begin_transaction(): context.run_migrations()
def test_load(tmp_path): c = tmp_path / 'config.toml' c.write_text('''[bot] bot_name = "botty" discord_api_key = "API_KEY"''') bot_config = config.load(str(c)) assert bot_config['bot_name'] == 'botty' assert bot_config['discord_api_key'] == 'API_KEY' assert 'logging' in bot_config assert bot_config.get('logging', {}).get('log_file') == 'botty.log'
def test_load_logging_config(tmp_path): c = tmp_path / 'config.toml' c.write_text('''[bot] bot_name = "botty" discord_api_key = "API_KEY" [bot.logging] log_file = "botty-log.log" log_to_console = true log_level = "warning"''') bot_config = config.load(str(c)) assert 'logging' in bot_config assert bot_config.get('logging', {}).get('log_file') == 'botty-log.log' assert bot_config.get('logging', {}).get('log_to_console') assert bot_config.get('logging', {}).get('log_level') == 'warning'
# This line sets up loggers basically. if config.config_file_name is not None: fileConfig(config.config_file_name) # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata target_metadata = mapper_registry.metadata # other values from the config, defined by the needs of env.py, # can be acquired: # my_important_option = config.get_main_option("my_important_option") # ... etc. bot_config = load(Path(__file__).resolve().parent.parent / 'config.toml') def run_migrations_offline() -> None: """Run migrations in 'offline' mode. This configures the context with just a URL and not an Engine, though an Engine is acceptable here as well. By skipping the Engine creation we don't even need a DBAPI to be available. Calls to context.execute() here emit the given string to the script output. """ url = bot_config.get('db_url', '')