MCPcopy
hub / github.com/Textualize/rich / test_highlight_regex_callable

Function test_highlight_regex_callable

tests/test_text.py:230–263  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

228
229
230def test_highlight_regex_callable():
231 text = Text("Vulnerability CVE-2018-6543 detected")
232 re_cve = r"CVE-\d{4}-\d+"
233 compiled_re_cve = re.compile(r"CVE-\d{4}-\d+")
234
235 def get_style(text: str) -> Style:
236 return Style.parse(
237 f"bold yellow link https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword={text}"
238 )
239
240 # string
241 count = text.highlight_regex(re_cve, get_style)
242 assert count == 1
243 assert len(text._spans) == 1
244 assert text._spans[0].start == 14
245 assert text._spans[0].end == 27
246 assert (
247 text._spans[0].style.link
248 == "https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=CVE-2018-6543"
249 )
250
251 # Clear the tracked _spans for the regular expression object's use
252 text._spans.clear()
253
254 # regular expression object
255 count = text.highlight_regex(compiled_re_cve, get_style)
256 assert count == 1
257 assert len(text._spans) == 1
258 assert text._spans[0].start == 14
259 assert text._spans[0].end == 27
260 assert (
261 text._spans[0].style.link
262 == "https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=CVE-2018-6543"
263 )
264
265
266def test_highlight_words():

Callers

nothing calls this directly

Calls 3

highlight_regexMethod · 0.95
TextClass · 0.90
clearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…