"""Regression tests for docs/detection/annotators.md tab structure.""" import ast import re from pathlib import Path import pytest _REPO_ROOT = Path(__file__).resolve().parent while not (_REPO_ROOT / "pyproject.toml").exists(): _REPO_ROOT = _REPO_ROOT.parent REPO_ROOT = _REPO_ROOT EXPECTED_ANNOTATOR_TAB_GROUPS: dict[str, list[str]] = { "Outlines": [ "Box", "RoundBox", "BoxCorner", "Circle", "Ellipse", "Polygon", ], "Shading": ["Color", "Halo", "Mask"], "Markers": ["Dot", "Triangle"], "Labels": ["Label", "RichLabel"], "Transformative": ["Blur", "Pixelate"], "Tracking & Aggregation": ["Trace", "HeatMap"], "Others": [ "PercentageBar", "Icon", "Background Color", "Comparison", ], } def _extract_annotator_tab_groups() -> dict[str, list[str]]: """Parse annotator tab structure from docs/detection/annotators.md. Returns: Mapping of category name to list of annotator tab labels within that category. """ docs_path = REPO_ROOT / "docs" / "detection" / "annotators.md" content = docs_path.read_text(encoding="utf-8") start_marker = '=== "Outlines"' end_marker = "Try Supervision Annotators on your own image" start = content.find(start_marker) if start == -1: pytest.fail( f"Could not find start marker {start_marker!r} in {docs_path} while " "parsing annotator example tab groups." ) end = content.find(end_marker, start) if end == -1: pytest.fail( f"Could not find end marker {end_marker!r} in {docs_path} while " "parsing annotator example tab groups." ) if end <= start: pytest.fail( f"End marker {end_marker!r} must appear after start marker " f"{start_marker!r} in {docs_path}." ) example_section = content[start:end] groups: dict[str, list[str]] = {} current_group = None for line in example_section.splitlines(): if match := re.match(r'^(?P\s*)=== "(?P