test descriptions

This commit is contained in:
Dobromir Popov
2026-07-11 22:25:30 +03:00
parent 7d259d7c9b
commit 7cf8d9bcf3
43 changed files with 876 additions and 265 deletions

View File

@@ -155,8 +155,8 @@ def _test_python() -> str:
return sys.executable
def _function_description(path: Path, function_name: str) -> str:
"""Return a concise source docstring, falling back to the test name."""
def _function_metadata(path: Path, function_name: str) -> tuple[str, set[str]]:
"""Read description and ``Tags:`` metadata from a test docstring."""
try:
tree = ast.parse(path.read_text())
base_name = function_name.split("[")[0]
@@ -167,14 +167,22 @@ def _function_description(path: Path, function_name: str) -> str:
None,
)
if function is not None:
doc = ast.get_docstring(function)
if doc:
return " ".join(doc.split())
doc = ast.get_docstring(function) or ""
tags: set[str] = set()
description_lines = []
for line in doc.splitlines():
match = re.match(r"^\s*Tags:\s*(.*)$", line, re.IGNORECASE)
if match:
tags.update(tag.strip().lower() for tag in match.group(1).split(",") if tag.strip())
elif line.strip():
description_lines.append(line.strip())
if description_lines:
return " ".join(description_lines), tags
except (OSError, SyntaxError):
pass
words = re.sub(r"([a-z])([A-Z])", r"\\1 \\2", function_name.split("[")[0])
words = words.replace("_", " ").strip()
return words[:1].upper() + words[1:] if words else "Test"
return (words[:1].upper() + words[1:] if words else "Test"), set()
class TestRunManager:
@@ -262,19 +270,23 @@ class TestRunManager:
def _test_metadata(self, node_id: str) -> dict:
module_path, function_name = node_id.split("::", 1)
module_name = Path(module_path).stem
tags: set[str] = set()
inferred_tags: set[str] = set()
for key, values in _MODULE_TAGS.items():
if key in module_name:
tags.update(values)
inferred_tags.update(values)
lowered = function_name.lower()
for key, values in _FUNCTION_TAGS.items():
if key in lowered:
tags.update(values)
inferred_tags.update(values)
description, documented_tags = _function_metadata(
self.repo_root / module_path, function_name
)
tags = inferred_tags | documented_tags
if not tags:
tags.add("general")
return {
"id": node_id,
"description": _function_description(self.repo_root / module_path, function_name),
"description": description,
"tags": sorted(tags),
}