Files
core/tests/test_source_validation.py
FoxVoland c16ed7915a [+!] all but small
some small modifications, tests added
2026-10-07 22:42:46 +03:00

30 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Проверки исходников, которые работают даже при ошибках импорта сервера."""
import ast
from pathlib import Path
def test_all_python_sources_compile():
"""Проверяет синтаксис всех серверных модулей и клиента без запуска и записи pyc."""
errors = []
root = Path(__file__).parents[1]
paths = list((root / "src").rglob("*.py")) + list((root / "examples").rglob("*.py"))
for path in sorted(paths):
try:
compile(path.read_text(encoding="utf-8"), str(path), "exec")
except SyntaxError as error:
errors.append(f"{path.relative_to(Path(__file__).parents[1])}:{error.lineno}: {error.msg}")
assert not errors, "\n".join(errors)
def test_every_test_has_a_description():
"""Проверяет наличие краткого docstring у каждого теста набора."""
missing = []
for path in Path(__file__).parent.glob("test_*.py"):
tree = ast.parse(path.read_text(encoding="utf-8"))
for node in ast.walk(tree):
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.name.startswith("test_"):
if not ast.get_docstring(node):
missing.append(f"{path.name}:{node.lineno}: {node.name}")
assert not missing, "\n".join(missing)