Update tests/test_utils_logcfg.py
Run CI Tests / test (push) Successful in 27s

This commit is contained in:
2025-07-28 14:49:48 +02:00
parent e5b6ce0f76
commit c87d284c08
+6 -13
View File
@@ -11,27 +11,21 @@ import tempfile
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from slic.utils.logcfg import *
# ANSI escape codes used for color testing
ANSI_CYAN = "\x1b[36m"
ANSI_GREEN = "\x1b[32m"
ANSI_MAGENTA = "\x1b[35m"
ANSI_RESET = "\x1b[0m"
# Register custom log levels once for the test module
@pytest.fixture(scope="module", autouse=True)
def setup_custom_levels():
# Add custom levels
add_log_Level(log, "LONG", logging.INFO + 5, func_name="long", color="cyan")
add_log_Level(log, "ENLARGE", logging.INFO + 6, func_name="enlarge", color="green")
add_log_Level(log, "LONG", logging.INFO + 5, func_name="long")
add_log_Level(log, "ENLARGE", logging.INFO + 6, func_name="enlarge")
logcfg("LONG") # Enable all levels >= LONG
# Test: add_log_Level()
@pytest.mark.parametrize("levelname, logfunc, message, ansi_color", [
("LONG", lambda msg: log.long(msg), "This is a LONG message", ANSI_CYAN),
("ENLARGE", lambda msg: log.enlarge(msg), "Please ENLARGE this!", ANSI_GREEN),
@pytest.mark.parametrize("levelname, logfunc, message", [
("LONG", lambda msg: log.long(msg), "This is a LONG message"),
("ENLARGE", lambda msg: log.enlarge(msg), "Please ENLARGE this!"),
])
def test_custom_levels_are_logged(levelname, logfunc, message, ansi_color, capsys):
def test_custom_levels_are_logged(levelname, logfunc, message, capsys):
# Call the custom log function
logzero.setup_default_logger()
logfunc(message)
@@ -40,7 +34,6 @@ def test_custom_levels_are_logged(levelname, logfunc, message, ansi_color, capsy
captured = capsys.readouterr().err
# Assert color, message, and ANSI reset code are present
assert ansi_color in captured, f"Expected color code {ansi_color} not found in log output"
assert message in captured, f"Expected log message '{message}' not found in output"
assert captured.strip().endswith(ANSI_RESET), "Missing ANSI reset code at end of log line"