Files
govoplan-scheduling/tests/test_module_boundary.py

36 lines
1.1 KiB
Python

from __future__ import annotations
import ast
import pathlib
import unittest
ROOT = pathlib.Path(__file__).resolve().parents[1]
class SchedulingModuleBoundaryTests(unittest.TestCase):
def test_runtime_source_does_not_import_poll_implementation_internals(self) -> None:
offenders: list[str] = []
source_root = ROOT / "src" / "govoplan_scheduling"
for path in source_root.rglob("*.py"):
tree = ast.parse(path.read_text(encoding="utf-8"))
imported_modules = [
node.module
for node in ast.walk(tree)
if isinstance(node, ast.ImportFrom) and node.module is not None
]
imported_modules.extend(
alias.name
for node in ast.walk(tree)
if isinstance(node, ast.Import)
for alias in node.names
)
if any(module.startswith("govoplan_poll") for module in imported_modules):
offenders.append(str(path.relative_to(ROOT)))
self.assertEqual([], offenders)
if __name__ == "__main__":
unittest.main()