35 lines
892 B
Python
35 lines
892 B
Python
import logging
|
|
|
|
from serato_doctor.logging import LOGGER_NAME, configure_logging
|
|
|
|
|
|
def test_logging_is_quiet_by_default(capsys):
|
|
logger = configure_logging()
|
|
|
|
logger.info("not visible")
|
|
|
|
assert capsys.readouterr().err == ""
|
|
|
|
|
|
def test_logging_writes_aggregate_progress_to_file(tmp_path):
|
|
log_path = tmp_path / "scan.log"
|
|
logger = configure_logging(log_file=log_path)
|
|
|
|
logger.info("Scanned %d disk tracks", 10)
|
|
|
|
contents = log_path.read_text(encoding="utf-8")
|
|
assert "INFO Scanned 10 disk tracks" in contents
|
|
|
|
|
|
def test_reconfiguring_logging_replaces_handlers():
|
|
configure_logging(verbose=True)
|
|
logger = configure_logging(verbose=True)
|
|
|
|
active_handlers = [
|
|
handler
|
|
for handler in logger.handlers
|
|
if not isinstance(handler, logging.NullHandler)
|
|
]
|
|
assert logger.name == LOGGER_NAME
|
|
assert len(active_handlers) == 1
|