From e28fbb181851ca16bc0ade9c371628f86c25adbc Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Sun, 19 Feb 2023 22:59:32 -0600 Subject: refactor custom logger and add tests --- tests/test_custom_logger.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/test_custom_logger.py (limited to 'tests/test_custom_logger.py') diff --git a/tests/test_custom_logger.py b/tests/test_custom_logger.py new file mode 100644 index 0000000..1062e41 --- /dev/null +++ b/tests/test_custom_logger.py @@ -0,0 +1,20 @@ +import pytest +from logging import DEBUG, INFO, WARNING, ERROR, CRITICAL +from typing import Callable + + +@pytest.mark.parametrize('log_level, starts_with, message', [ + (DEBUG, '[DEBUG]', 'first message'), + (INFO, 'second message', 'second message'), + (WARNING, '\x1b[33m[WARNING]', 'third message'), + (ERROR, '\x1b[31m[ERROR]', 'fourth message'), + (CRITICAL, '\x1b[31;1m[CRITICAL]', 'fifth message'), +]) +def test_log_levels(log_level: int, + starts_with: str, + message: str, + logger: Callable, + capture_stdout: dict[str, str | int]) -> None: + logger.log(log_level, message) + assert str(capture_stdout['stdout']).startswith(starts_with) + assert message in str(capture_stdout['stdout']) -- cgit v1.2.3-54-g00ecf