Coverage for tests / unit / utils / console / test_logger_levels.py: 100%
34 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Unit tests for ThreadSafeConsoleLogger logging level methods.
3Tests cover info, debug, warning, error, and success logging methods
4and verify they use appropriate colors and formatting.
5"""
7from __future__ import annotations
9from unittest.mock import patch
11import pytest
12from assertpy import assert_that
14from lintro.utils.console.logger import ThreadSafeConsoleLogger
17def test_info_delegates_to_console_output(logger: ThreadSafeConsoleLogger) -> None:
18 """Verify info() delegates to console_output without color styling.
20 The info method is a convenience wrapper that passes messages directly
21 to console_output without any color formatting.
23 Args:
24 logger: ThreadSafeConsoleLogger instance fixture.
25 """
26 with patch.object(logger, "console_output") as mock_output:
27 logger.info("info message")
28 mock_output.assert_called_once_with("info message")
31def test_debug_uses_loguru_logger(logger: ThreadSafeConsoleLogger) -> None:
32 """Verify debug() uses loguru's debug level instead of console output.
34 Debug messages go to the loguru logger for proper debug-level filtering,
35 rather than always appearing on the console.
37 Args:
38 logger: ThreadSafeConsoleLogger instance fixture.
39 """
40 with patch("lintro.utils.console.logger.logger.debug") as mock_debug:
41 logger.debug("debug message")
42 mock_debug.assert_called_once_with("debug message")
45def test_warning_outputs_yellow_text(logger: ThreadSafeConsoleLogger) -> None:
46 """Verify warning() outputs messages in yellow color with WARNING prefix.
48 Warning messages should be visually distinct using yellow coloring
49 and a WARNING prefix to indicate potential issues.
51 Args:
52 logger: ThreadSafeConsoleLogger instance fixture.
53 """
54 with patch.object(logger, "console_output") as mock_output:
55 logger.warning("warning message")
56 mock_output.assert_called_once_with("WARNING: warning message", color="yellow")
59def test_error_outputs_red_text(logger: ThreadSafeConsoleLogger) -> None:
60 """Verify error() outputs messages in red color with ERROR prefix.
62 Error messages use red coloring to clearly indicate problems
63 that need immediate attention.
65 Args:
66 logger: ThreadSafeConsoleLogger instance fixture.
67 """
68 with (
69 patch("lintro.utils.console.logger.click.echo") as mock_echo,
70 patch("lintro.utils.console.logger.click.style") as mock_style,
71 patch("lintro.utils.console.logger.logger"),
72 ):
73 mock_style.return_value = "styled"
74 logger.error("error message")
75 mock_style.assert_called_once_with("ERROR: error message", fg="red", bold=True)
76 mock_echo.assert_called_once_with("styled")
77 assert_that(logger._messages).contains("ERROR: error message")
80def test_success_outputs_green_text_with_checkmark(
81 logger: ThreadSafeConsoleLogger,
82) -> None:
83 """Verify success() outputs messages in green with checkmark emoji prefix.
85 Success messages include a checkmark emoji and use green coloring
86 to clearly indicate successful completion of operations.
88 Args:
89 logger: ThreadSafeConsoleLogger instance fixture.
90 """
91 with patch.object(logger, "console_output") as mock_output:
92 logger.success("success message")
93 mock_output.assert_called_once_with(
94 text="\u2705 success message",
95 color="green",
96 )
99@pytest.mark.parametrize(
100 ("method", "expected_color"),
101 [
102 pytest.param("warning", "yellow", id="warning-yellow"),
103 pytest.param("success", "green", id="success-green"),
104 ],
105)
106def test_logging_methods_use_correct_colors(
107 logger: ThreadSafeConsoleLogger,
108 method: str,
109 expected_color: str,
110) -> None:
111 """Verify each logging level method uses its designated color.
113 Each logging method has an associated color to provide visual distinction
114 between message severity levels in console output.
116 Args:
117 logger: ThreadSafeConsoleLogger instance fixture.
118 method: The logging method name to test.
119 expected_color: The expected color for the logging method.
120 """
121 with patch.object(logger, "console_output") as mock_output:
122 getattr(logger, method)("test message")
123 call_kwargs = mock_output.call_args
124 assert_that(
125 call_kwargs.kwargs.get(
126 "color",
127 call_kwargs.args[1] if len(call_kwargs.args) > 1 else None,
128 ),
129 ).is_equal_to(expected_color)