Underline bar renderable

This commit is contained in:
Darren Burns
2022-01-31 13:03:48 +00:00
parent 9e10f38d6b
commit 5651e97a64
5 changed files with 234 additions and 95 deletions

24
tests/utilities/render.py Normal file
View File

@@ -0,0 +1,24 @@
import io
import re
from rich.console import Console, RenderableType
re_link_ids = re.compile(r"id=[\d\.\-]*?;.*?\x1b")
def replace_link_ids(render: str) -> str:
"""Link IDs have a random ID and system path which is a problem for
reproducible tests.
"""
return re_link_ids.sub("id=0;foo\x1b", render)
def render(renderable: RenderableType, no_wrap: bool = False) -> str:
console = Console(
width=100, file=io.StringIO(), color_system="truecolor", legacy_windows=False
)
console.print(renderable, no_wrap=no_wrap)
output = replace_link_ids(console.file.getvalue())
return output