# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence. """DEBUG that stays readable: the bot's own loggers, not its libraries'.""" from __future__ import annotations import logging import pytest from signal_bot.logging_setup import NOISY, NOISY_FLOOR, configure @pytest.fixture(autouse=True) def _restore_levels() -> None: """Put every logger this module touches back, so tests stay independent.""" root = logging.getLogger().level before = {name: logging.getLogger(name).level for name in NOISY} yield logging.getLogger().setLevel(root) for name, level in before.items(): logging.getLogger(name).setLevel(level) def test_the_bots_own_level_is_what_was_asked_for() -> None: configure("DEBUG") assert logging.getLogger("signal_bot.dispatcher").getEffectiveLevel() == logging.DEBUG def test_debug_does_not_turn_on_the_noisy_libraries() -> None: """httpcore logs both ends of every connection, every 30 seconds.""" configure("DEBUG") for name in NOISY: assert logging.getLogger(name).level == NOISY_FLOOR def test_the_floor_applies_at_info_too() -> None: """httpx logged one "HTTP Request" line per listing poll, at INFO.""" logging.getLogger("httpx").setLevel(logging.NOTSET) configure("INFO") assert logging.getLogger("httpx").level == NOISY_FLOOR assert logging.getLogger("signal_bot").getEffectiveLevel() == logging.INFO def test_warnings_from_a_noisy_library_still_get_through() -> None: """The floor is a floor, not a gag: a real httpx warning is worth seeing.""" configure("DEBUG") assert logging.getLogger("httpx").isEnabledFor(logging.WARNING) assert not logging.getLogger("httpx").isEnabledFor(logging.INFO)