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
+9 -29
View File
@@ -10,16 +10,12 @@ from logwatcher.parser import parse_file
def _pattern_name_to_filename(name: str) -> str:
"""
Returns the fixture corresponding to the error code name
"""
"""Return the fixture corresponding to the error code name."""
return f"CR_{name.lower()}.txt"
def _read_fixture(path: Path) -> str:
"""
Read a file with fallback Windows-1252.
"""
"""Read a file with fallback Windows-1252."""
try:
content = path.read_text(encoding="utf-8")
except UnicodeDecodeError:
@@ -31,10 +27,7 @@ def _read_fixture(path: Path) -> str:
@pytest.mark.parametrize("name, pattern", N2_PATTERNS.items())
def test_pattern_matches_fixture(valid_log_dir, name, pattern):
"""
Assert each N2 pattern must match at least one line in its fixture.
"""
"""Assert each N2 pattern must match at least one line in its fixture."""
fixture = valid_log_dir / _pattern_name_to_filename(name)
if not fixture.exists():
msg = f"No fixture named '{fixture}'"
@@ -58,9 +51,7 @@ def test_pattern_matches_fixture(valid_log_dir, name, pattern):
def test_patterns_do_not_overlap():
"""
Assert that a log line can match only one N2 pattern.
"""
"""Assert that a log line can match only one N2 pattern."""
fixtures_dir = FIXTURE_PATH
for fixture in fixtures_dir.glob("CR_*.txt"):
line_list = [
@@ -79,10 +70,7 @@ def test_patterns_do_not_overlap():
def test_no_orphan_fixtures():
"""
Assert that a fixture exist only if its associated pattern exists.
Aucun fichier de fixture ne doit exister sans pattern associé.
"""
"""Assert that a fixture exist only if its associated pattern exists."""
expected = {f"CR_{name.lower()}.txt" for name in N2_PATTERNS}
actual = {f.name for f in FIXTURE_PATH.glob("CR_*.txt")}
orphan = actual - expected
@@ -90,9 +78,7 @@ def test_no_orphan_fixtures():
def test_classify_log_entries_all_relevant(valid_log_dir: Path):
"""
Must return an empty irrelevant log entry list
"""
"""Must return an empty irrelevant log entry list."""
log_file = valid_log_dir / "only_relevant_logs.txt"
log_entries = parse_file(log_file)
@@ -103,9 +89,7 @@ def test_classify_log_entries_all_relevant(valid_log_dir: Path):
def test_classify_log_entries_none_relevant(valid_log_dir: Path):
"""
Must return an empty relevant log entry list
"""
"""Must return an empty relevant log entry list."""
log_file = valid_log_dir / "no_relevant_logs.txt"
log_entries = parse_file(log_file)
@@ -116,9 +100,7 @@ def test_classify_log_entries_none_relevant(valid_log_dir: Path):
def test_classify_log_entries_mixed(valid_log_dir: Path):
"""
Test classification on relevant and irrelevant log entry list
"""
"""Test classification on relevant and irrelevant log entry list."""
log_file = valid_log_dir / "mixed_logs.txt"
log_entries = parse_file(log_file)
@@ -129,9 +111,7 @@ def test_classify_log_entries_mixed(valid_log_dir: Path):
def test_classify_log_entries_empty_log_entries(invalid_log_dir: Path):
"""
Test classification on an empty log entry list
"""
"""Test classification on an empty log entry list."""
empty_file = invalid_log_dir / "empty_file.txt"
log_entries = parse_file(empty_file)