Files
computer-playbook/tests/integration/ansible/jinja/test_syntax.py
kevinveenbirkenbachandClaude Opus 4.7 4ac7a95ec6 refactor(tests): split overflowing folders into thematic subdirs
Reorganises four folders that exceeded the 12-item readability limit:

- tests/lint/repository/ (27 -> 11): structure/, naming/, documentation/,
  python/, dependencies/, shell/, yaml/, network/, settings/
- tests/integration/ (25 -> 7): ansible/, infrastructure/, iam/, meta/
  (24 sibling dirs grouped under 4 super-categories)
- tests/integration/roles/ (13 -> 10): naming/, playwright/, dashboard/
- tests/unit/utils/ (15 -> 12): certs/ for 3 cert/TLS test files

Renames 7 test files whose name duplicated the new folder name
(e.g. test_no_direct_yaml_calls.py -> yaml/test_no_direct_calls.py,
test_dashboard_integration_scope.py -> dashboard/test_integration_scope.py).

Adjusts parents[N] in moved __init__.py files, fixes __file__-based
path resolution in 8 tests, updates self-path whitelists, and uses
absolute imports for PROJECT_ROOT re-exports (ruff TID252).

Adds README.md to each new subfolder following the existing scope
template. Updates all docs links (suppression.md, base.md, email.md,
playwright spec/parity docs, 005-/019- requirements) to new paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 14:23:32 +02:00

31 lines
929 B
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 unittest
from jinja2 import Environment, exceptions, select_autoescape
from utils.cache.files import iter_project_files_with_content
class TestJinja2Syntax(unittest.TestCase):
def test_all_j2_templates_have_valid_syntax(self):
"""
Recursively find all .j2 files from the project root and try to parse them.
A SyntaxError in any template fails the test.
"""
env = Environment(autoescape=select_autoescape())
failures = []
for path, src in iter_project_files_with_content(extensions=(".j2",)):
try:
env.parse(src)
except exceptions.TemplateSyntaxError as e:
failures.append(f"{path}:{e.lineno} – {e.message}")
if failures:
self.fail(
"Syntax errors found in Jinja2 templates:\n" + "\n".join(failures)
)
if __name__ == "__main__":
unittest.main()