21 lines
908 B
Python
21 lines
908 B
Python
"""B1 — `plm_engine` is framework-free: it never imports Django, the old FastAPI stack or a database layer (ADR-59)."""
|
|||
|
|
|
||
|
|
import ast
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
ENGINE = Path(__file__).resolve().parents[2] / "plm_engine"
|
||
|
|
FORBIDDEN = {"django", "apps", "app", "config", "sqlalchemy", "fastapi", "alembic"}
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize("path", sorted(ENGINE.rglob("*.py")), ids=lambda p: str(p.relative_to(ENGINE)))
|
||
|
|
def test_the_engine_imports_no_framework(path):
|
||
|
|
tree = ast.parse(path.read_text())
|
||
|
|
imported = set()
|
||
|
|
for node in ast.walk(tree):
|
||
|
|
if isinstance(node, ast.Import):
|
||
|
|
imported |= {alias.name.split(".")[0] for alias in node.names}
|
||
|
|
elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module:
|
||
|
|
imported.add(node.module.split(".")[0])
|
||
|
|
assert not imported & FORBIDDEN, f"{path.name} imports {sorted(imported & FORBIDDEN)}"
|