49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
"""The engine knows no subject, and the toy Workflow borrows nothing from the Reference's."""
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
REPO = Path(__file__).parents[1]
|
|
ENGINE = REPO / "execution_engine"
|
|
TOY = REPO / "tests" / "toy"
|
|
_IMPORT = re.compile(r"^\s*(?:from|import)\s+([\w.]+)", re.MULTILINE)
|
|
# What the Reference's engine named directly, before a Workflow supplied it.
|
|
_REFERENCE_NAMES = re.compile(
|
|
r"\b(DeliverableKind|PhaseId|DEPENDENCY_GRAPH|PHASE_ORDER|GUIDE_FILENAME)\b"
|
|
)
|
|
|
|
|
|
def imports_of(folder: Path) -> dict[str, set[str]]:
|
|
return {
|
|
path.relative_to(REPO).as_posix(): set(_IMPORT.findall(path.read_text("utf-8")))
|
|
for path in folder.rglob("*.py")
|
|
}
|
|
|
|
|
|
def test_the_engine_imports_nothing_from_its_tests():
|
|
offending = {
|
|
name: sorted(module for module in modules if module.split(".")[0] == "tests")
|
|
for name, modules in imports_of(ENGINE).items()
|
|
}
|
|
|
|
assert {name: found for name, found in offending.items() if found} == {}
|
|
|
|
|
|
def test_the_engine_names_no_deliverable_of_the_reference():
|
|
offending = [
|
|
path.relative_to(REPO).as_posix()
|
|
for path in ENGINE.rglob("*.py")
|
|
if _REFERENCE_NAMES.search(path.read_text("utf-8"))
|
|
]
|
|
|
|
assert offending == []
|
|
|
|
|
|
def test_the_toy_workflow_uses_nothing_of_the_references_subject():
|
|
offending = {
|
|
name: sorted(m for m in modules if m.startswith("tests.reference_workflow"))
|
|
for name, modules in imports_of(TOY).items()
|
|
}
|
|
|
|
assert {name: found for name, found in offending.items() if found} == {}
|