38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import ast
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
class PostboxModuleBoundaryTests(unittest.TestCase):
|
|
def test_backend_does_not_import_sibling_module_implementations(self) -> None:
|
|
root = Path(__file__).parents[1] / "src" / "govoplan_postbox"
|
|
forbidden = (
|
|
"govoplan_access",
|
|
"govoplan_campaign",
|
|
"govoplan_files",
|
|
"govoplan_identity",
|
|
"govoplan_idm",
|
|
"govoplan_mail",
|
|
"govoplan_organizations",
|
|
"govoplan_portal",
|
|
)
|
|
violations: list[str] = []
|
|
for path in root.rglob("*.py"):
|
|
tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
|
|
for node in ast.walk(tree):
|
|
names: list[str] = []
|
|
if isinstance(node, ast.Import):
|
|
names.extend(alias.name for alias in node.names)
|
|
elif isinstance(node, ast.ImportFrom) and node.module:
|
|
names.append(node.module)
|
|
for name in names:
|
|
if name.startswith(forbidden):
|
|
violations.append(f"{path.relative_to(root)}: {name}")
|
|
self.assertEqual([], violations)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|