proposemodes.py¶
clew/wiki/proposemodes.py
A reviewed draft of which assertion fails into which declared mode, and its application.
apply
tuple[int, list[str]] clew.wiki.proposemodes.apply(Path repo_root, list[dict[str, Any]] entries)
Write the accepted proposals as inline markers.
Source · 21 lines
def apply(repo_root: Path, entries: list[dict[str, Any]]) -> tuple[int, list[str]]:
"""ONLY `status: accepted` with a `proposed` id is written. A line that no longer starts with
the assertion's statement (the file moved on since the draft) is refused and named, never
rewritten in place; so is one that already carries a marker.
@brief Apply a reviewed draft.
@return Count and refusals.
"""
written, refused = 0, []
by_file: dict[str, list[dict[str, Any]]] = {}
for entry in entries:
for item in entry.get("assertions") or []:
if item.get("status") == "accepted" and item.get("proposed"):
by_file.setdefault(str(entry["file"]), []).append(item)
for file, items in by_file.items():
count, problems = _apply_file(repo_root / file, file, items)
written += count
refused += problems
return written, refused
Activity · 11 steps
Requirements
proposals
list[dict[str, Any]] clew.wiki.proposemodes.proposals(Path db, Path repo_root, list[str]|None files=None)
The draft: per test covering a requirement with declared modes, its unmarked assertions.
Source · 28 lines
def proposals(db: Path, repo_root: Path, files: list[str] | None = None) -> list[dict[str, Any]]:
"""@brief Draft. @return Entries."""
conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)
try:
tests = _covering_tests(conn)
meanings = dict(conn.execute("SELECT mode_id, meaning FROM failure_modes"))
except sqlite3.OperationalError:
return []
finally:
conn.close()
out = []
for (name, file, start, end), modes in sorted(tests.items(), key=lambda t: (t[0][1], t[0][2])):
if files is not None and file not in files:
continue
unmarked = _unmarked(repo_root, file, start, end)
if unmarked:
out.append(
{
"test": name,
"file": file,
"line": start,
"modes": [{"id": m, "meaning": meanings.get(m, "")} for m in modes],
"assertions": unmarked,
}
)
return out