style(project): 🎨 improve all docstrings and centralize mail variables in mail_utils

This commit is contained in:
2026-09-17 12:59:07 +02:00
parent 6909ee7acf
commit 5e43a0cbb8
17 changed files with 116 additions and 101 deletions
+17 -14
View File
@@ -1,14 +1,3 @@
"""
this module contains all tests logging-related :
- the logger should have at least one StreamHandler and one FileHandler each time
logwatcher is launched.
- the StreamHandler must watch at an error level
- the FileHandler must watch at a debug
level
-
"""
import logging
import re
from logging import DEBUG, ERROR, INFO, WARNING, FileHandler, StreamHandler, getLogger
@@ -20,6 +9,7 @@ from logwatcher.logging_config import _setup_formatter, _setup_handler, setup_lo
def test_setup_handler(tmp_log_file):
"""Assert `setup_handler` instanciate one StreamHandler and one FileHandler."""
formatter = _setup_formatter()
handler = _setup_handler(formatter=formatter, level=DEBUG)
assert isinstance(handler, StreamHandler)
@@ -29,6 +19,10 @@ def test_setup_handler(tmp_log_file):
def test_count_of_handler(tmp_log_file):
"""Assert `setup_handler` instanciate exactly one StreamHandler and one FileHandler.
Must have exactly two handlers in total.
"""
logger = getLogger()
count_file_handler = 0
count_stream_handler = 0
@@ -46,6 +40,10 @@ def test_count_of_handler(tmp_log_file):
def test_type_of_handlers():
"""Assert each handlers capture the right log level and use the right log format.
FileHandler must capute DEBUG logs while StreamHandler only capture ERROR logs.
"""
logger = logging.getLogger("logwatcher")
for handler in logger.handlers:
if isinstance(handler, FileHandler):
@@ -59,8 +57,9 @@ def test_type_of_handlers():
def test_modified_format():
"""
when starting, the logger is first intialized, thus two handlers are at position
"""Assert `setup_logging` allow to use another log format.
When starting, the logger is first intialized, thus two handlers are at position
1 and 2 in logger.handlers list.
"""
logger = setup_logging()
@@ -82,6 +81,10 @@ def test_modified_format():
def test_logging_in_correct_path(tmp_log_file):
"""Assert log file is correctly written in output directory.
Check content of the file. It must contain logs from CRITICAL to DEBUG level.
"""
logger = logging.getLogger("logwatcher")
# must be both in file and stdout
logger.critical("hi- BYE")
@@ -100,7 +103,7 @@ def test_logging_in_correct_path(tmp_log_file):
for line in content:
assert re.search(regex, line)
# test critical to warning
# test from critical to debug logs
assert re.search(r"CRITICAL: hi- BYE", content[0])
assert re.search(r"ERROR: hi... ok, bye", content[1])
assert re.search(r"WARNING: hi, are you alright?", content[2])