reach.py¶
clew/guard/reach.py
What a change reaches beyond its own tags: covering tests, and requirements through callers.
covering_tests
dict[str, list[TestRef]] clew.guard.reach.covering_tests(Path repo_root, set[str] req_ids, set[str] catalog, list[str]|None files=None, dict[str, Any]|None config=None)
The tests covering each requirement, read from the test tree.
Source · 19 lines
def covering_tests(
repo_root: Path,
req_ids: set[str],
catalog: set[str],
files: list[str] | None = None,
config: dict[str, Any] | None = None,
) -> dict[str, list[TestRef]]:
config = config or {}
patterns = tuple(config.get("test_paths") or TEST_PATH_FACTS)
out: dict[str, list[TestRef]] = {}
for rel in files if files is not None else _tracked(repo_root):
if not is_test_path(rel, patterns):
continue
for req_id, ref in _file_tests(repo_root, rel, catalog, config):
if req_id in req_ids and ref not in out.setdefault(req_id, []):
out[req_id].append(ref)
return out
Activity · 10 steps
Requirements
own_reqs
list[str] clew.guard.reach.Reach.own_reqs(self, Any changed)
The requirements the changed function's own index row carries.
Source · 20 lines
def own_reqs(self, changed: Any) -> list[str]:
if self.db is None:
return []
conn = sqlite3.connect(f"file:{self.db}?mode=ro", uri=True)
try:
rowids = _rowids(conn, changed)
marks = ",".join("?" * len(rowids))
rows = (
conn.execute(
f"SELECT DISTINCT req_id FROM req_edges WHERE memberdef_rowid IN ({marks})",
rowids,
).fetchall()
if rowids
else []
)
finally:
conn.close()
return sorted(str(r) for (r,) in rows)
Activity · 8 steps
Requirements
tests_for
dict[str, list[TestRef]] clew.guard.reach.Reach.tests_for(self, set[str] req_ids, set[str] catalog)
The covering tests for these requirements.
Source · 9 lines
def tests_for(self, req_ids: set[str], catalog: set[str]) -> dict[str, list[TestRef]]:
if self.tests is None:
self.tests = (
covering_tests(self.repo_root, req_ids, catalog, config=self.config)
if self.repo_root is not None
else {}
)
return self.tests
Activity · 3 steps
Requirements
via
list[tuple[str, list[str]]] clew.guard.reach.Reach.via(self, Any changed)
The requirements a function without @req reaches through its callers.
Source · 9 lines
def via(self, changed: Any) -> list[tuple[str, list[str]]]:
if self.db is None:
return []
conn = sqlite3.connect(f"file:{self.db}?mode=ro", uri=True)
try:
return _walk(conn, _rowids(conn, changed))
finally:
conn.close()