Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion alembic/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations

import logging
from argparse import ArgumentParser
from argparse import Namespace
from configparser import ConfigParser
Expand Down
41 changes: 20 additions & 21 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,32 @@ def test_config_logging_with_file(self):
handler.setLevel(logging.INFO)

logger = logging.getLogger("alembic.config")
# logger.x=True
with (
mock.patch.object(logger, "handlers", []),
mock.patch.object(logger, "level", logging.NOTSET),
):
logger.addHandler(handler)
logger.setLevel(logging.INFO)

old_level = logger.level
logger.addHandler(handler)
logger.setLevel(logging.INFO)

try:
cfg = _write_config_file(
"""
[alembic]
script_location = %(base_path)s/db/migrations
"""
)
test_cfg = config.Config(
cfg.config_file_name, config_args=dict(base_path="/tmp")
cfg.config_file_name,
config_args=dict(base_path="/tmp")
)
test_cfg.cmd_opts = mock.Mock(verbose=True)

_ = test_cfg.file_config

output = buf.getvalue()
assert "Loading config from file" in output
assert cfg.config_file_name.replace("/", os.path.sep) in output
assert cfg.config_file_name in output

finally:
logger.removeHandler(handler)
logger.setLevel(old_level)

def tearDown(self):
clear_staging_env()
Expand All @@ -87,25 +89,22 @@ def test_config_logging_without_file(self):
handler.setLevel(logging.INFO)

logger = logging.getLogger("alembic.config")
with (
mock.patch.object(logger, "handlers", []),
mock.patch.object(logger, "level", logging.NOTSET),
):

logger.addHandler(handler)
logger.setLevel(logging.INFO)
old_level = logger.level
logger.addHandler(handler)
logger.setLevel(logging.INFO)

try:
test_cfg = config.Config()
test_cfg.cmd_opts = mock.Mock(verbose=True)

_ = test_cfg.file_config

output = buf.getvalue()
assert "No config file provided" in output
assert (
test_cfg.config_file_name is None
and test_cfg._config_file_path is None
)
assert test_cfg.config_file_name is None and test_cfg._config_file_path is None
finally:
logger.removeHandler(handler)
logger.setLevel(old_level)

def test_config_no_file_main_option(self):
cfg = config.Config()
Expand Down