"""Проверки исходников, которые работают даже при ошибках импорта сервера.""" 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)