""" Tests for CSS tooltip changes (issue #1775). Verifies that custom data-tooltip / has-tooltip markup is applied correctly across index.html, style.css, and i18n.js — replacing native title="" attributes with a faster, CSS-driven tooltip system. Run: /root/hermes-agent/venv/bin/python -m pytest tests/test_css_tooltips.py -v """ import os import re import unittest # --------------------------------------------------------------------------- # Paths # --------------------------------------------------------------------------- BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) INDEX_HTML = os.path.join(BASE_DIR, "static", "index.html") STYLE_CSS = os.path.join(BASE_DIR, "static", "style.css") I18N_JS = os.path.join(BASE_DIR, "static", "i18n.js") def _read(path): with open(path, encoding="utf-8") as fh: return fh.read() # --------------------------------------------------------------------------- # Lightweight HTML tag extractor (stdlib-only) # --------------------------------------------------------------------------- _TAG_RE = re.compile(r"<(\w+)([^>]*?)(?:/>|>)", re.DOTALL) def _extract_tags(html, class_filter=None): """Return a list of dicts {tag, attrs_str, line} for tags whose class attribute contains all tokens in *class_filter* (if given).""" results = [] for m in _TAG_RE.finditer(html): tag = m.group(1) attrs_str = m.group(2) if class_filter: cls_match = re.search(r'class="([^"]*)"', attrs_str) if not cls_match: continue classes = cls_match.group(1).split() if not all(tok in classes for tok in class_filter): continue results.append({"tag": tag, "attrs": attrs_str, "match": m}) return results def _has_attr(attrs_str, attr_name): """Check if a bare attribute name is present in the attrs string. Handles both attr_name and attr_name="...".""" return bool(re.search(r'\b' + re.escape(attr_name) + r'(?:=|\s|>)', attrs_str)) def _get_attr(attrs_str, attr_name): """Get the value of attr="..." from an attrs string, or None. Uses a negative lookbehind to avoid matching 'title' inside 'data-i18n-title' or similar prefixed attributes. """ # Preceding char must be whitespace or start-of-string — not a letter/hyphen. m = re.search(r'(?....""" m = re.search( r'