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
+21 -13
View File
@@ -8,8 +8,8 @@ from logwatcher.parser import parse_file, parse_line, parse_lines
@pytest.fixture(name="empty_log_file")
def empty_log_file_fixture(invalid_log_dir: Path) -> Path:
"""
Path of an empty log file.
"""Path of an empty log file.
Ensures the parser does not raise an exception
and returns an empty list.
"""
@@ -18,8 +18,8 @@ def empty_log_file_fixture(invalid_log_dir: Path) -> Path:
@pytest.fixture(name="bad_log_file")
def bad_log_file_fixture(invalid_log_dir: Path) -> Path:
"""
Path of a file containing only incorrectly formatted lines.
"""Path of a file containing only incorrectly formatted lines.
Each line fails at a different point in LOG_PATTERN
(invalid IP, missing timestamp, missing DOSSIER EN COURS, etc.).
No LogEntry should be produced.
@@ -29,8 +29,8 @@ def bad_log_file_fixture(invalid_log_dir: Path) -> Path:
@pytest.fixture(name="specific_logs")
def specific_logs_fixture(valid_log_dir: Path) -> Path:
"""
Single log lines chosen to cover specific cases.
"""Single log lines chosen to cover specific cases.
Each line is structurally valid and must be parsed
successfully. Used for unit tests of parse_line().
"""
@@ -38,8 +38,8 @@ def specific_logs_fixture(valid_log_dir: Path) -> Path:
def test_parse_line(specific_logs: Path):
"""
Every structurally valid line produces a complete LogEntry.
"""Every structurally valid line produces a complete LogEntry.
Ensures no required field is empty or None after parsing
a line conforming to the LAME MDC format.
"""
@@ -59,8 +59,8 @@ def test_parse_line(specific_logs: Path):
def test_parse_empty_line():
"""
An empty or structurally invalid line returns None.
r"""An empty or structurally invalid line returns None.
Covered cases:
- Empty string.
- Directory header (\"Répertoire scanné : \\\\...\").
@@ -73,6 +73,7 @@ def test_parse_empty_line():
def test_parse_lines():
"""Assert parse_log find the valid logs among a mixed of logs."""
# mix of valid and invalid logs. Have 4 valid logs
original_lines = [
r"Répertoire scanné : \\192.168.13.22\e\MDC_240\Logs",
@@ -92,6 +93,7 @@ def test_parse_lines():
def test_parse_valid_lines(specific_logs: Path):
"""Assert parse_lines works for all valid lines."""
# selected valid logs
with open(specific_logs, "r") as file:
log_lines = file.readlines()
@@ -102,20 +104,24 @@ def test_parse_valid_lines(specific_logs: Path):
def test_parse_empty_lines(empty_log_file: Path):
"""Assert parsing an empty line does not raise an error and return an empty log entry list."""
with open(empty_log_file, "r") as file:
log_entries = parse_lines(file.readlines())
assert len(log_entries) == 0
def test_parse_invalid_lines(bad_log_file: Path):
"""Assert parsing an invalid line does not raise an error and return an empty log entry list."""
with open(bad_log_file, "r") as file:
log_entries = parse_lines(file.readlines())
assert len(log_entries) == 0
def test_parse_files(original_log_dir: Path, valid_log_dir: Path):
"""
"""Assert parse_files works with real life logs.
Each real log file produces at least one valid LogEntry.
Integration test: files provided by technicians contain
a mix of valid lines and lines to be ignored.
Ensures the parser extracts at least one entry per file.
@@ -130,7 +136,8 @@ def test_parse_files(original_log_dir: Path, valid_log_dir: Path):
def test_parse_empty_file(empty_log_file):
"""
"""Assert parsing an empty file does not raise an error and return an empty log entrt list instead.
An empty log file can be parsed and must returns an
empty LogEntry list.
"""
@@ -139,7 +146,8 @@ def test_parse_empty_file(empty_log_file):
def test_parse_bad_file(bad_log_file):
"""
"""Assert parsing a bad file does not raise an error and return an empty log entry list instead.
A file containing only invalid lines produces nothing.
Any line that does not match the LAME MDC structure
(IP, timestamps, DOSSIER EN COURS, error message)