test: don't require translations for debug messages

This commit is contained in:
sebthom
2025-04-07 22:40:30 +02:00
parent aeaf77e5d4
commit 21835d9d86

View File

@@ -62,6 +62,7 @@ def _get_function_name(node: ast.AST) -> str:
Returns:
The function name or "module" for module-level code
"""
def find_parent_context(n: ast.AST) -> tuple[str | None, str | None]:
"""Find the containing class and function names."""
class_name = None
@@ -83,7 +84,7 @@ def _get_function_name(node: ast.AST) -> str:
return "module" # For module-level code
def _extract_log_messages(file_path: str) -> MessageDict:
def _extract_log_messages(file_path: str, exclude_debug:bool = False) -> MessageDict:
"""
Extract all translatable messages from a Python file with their function context.
@@ -127,7 +128,7 @@ def _extract_log_messages(file_path: str) -> MessageDict:
if (isinstance(node.func, ast.Attribute) and
isinstance(node.func.value, ast.Name) and
node.func.value.id in {'LOG', 'logger', 'logging'} and
node.func.attr in {'debug', 'info', 'warning', 'error', 'critical'}):
node.func.attr in {None if exclude_debug else 'debug', 'info', 'warning', 'error', 'critical'}):
if node.args:
msg = extract_string_value(node.args[0])
if msg:
@@ -154,7 +155,7 @@ def _extract_log_messages(file_path: str) -> MessageDict:
return messages
def _get_all_log_messages() -> dict[str, MessageDict]:
def _get_all_log_messages(exclude_debug:bool = False) -> dict[str, MessageDict]:
"""
Get all translatable messages from all Python files in the project.
@@ -191,7 +192,7 @@ def _get_all_log_messages() -> dict[str, MessageDict]:
relative_path = os.path.relpath(file_path, src_dir)
if relative_path.startswith('resources/'):
continue
messages = _extract_log_messages(file_path)
messages = _extract_log_messages(file_path, exclude_debug)
if messages:
module_path = os.path.join('kleinanzeigen_bot', relative_path)
module_path = module_path.replace(os.sep, '/')
@@ -323,7 +324,7 @@ def test_all_log_messages_have_translations(lang: str) -> None:
This test ensures that no untranslated messages exist in the codebase.
"""
messages_by_file = _get_all_log_messages()
messages_by_file = _get_all_log_messages(exclude_debug = True)
translations = _get_translations_for_language(lang)
missing_translations = []
@@ -373,7 +374,7 @@ def test_no_obsolete_translations(lang: str) -> None:
function:
"original message": "translated message"
"""
messages_by_file = _get_all_log_messages()
messages_by_file = _get_all_log_messages(exclude_debug = False)
translations = _get_translations_for_language(lang)
obsolete_items: list[tuple[str, str, str]] = []