diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:18:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:18:28 +0000 |
commit | f8363b456f1ab31ee56abad579b215af195093d5 (patch) | |
tree | b1500c675c2e0a55fb75721a854e1510acf7c862 /tests/render.py | |
parent | Initial commit. (diff) | |
download | rich-upstream.tar.xz rich-upstream.zip |
Adding upstream version 9.11.0.upstream/9.11.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/render.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/render.py b/tests/render.py new file mode 100644 index 0000000..a2435c5 --- /dev/null +++ b/tests/render.py @@ -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 |