rich/tests/test_log.py

38 lines
1.9 KiB
Python
Raw Normal View History

2020-06-15 10:51:52 +00:00
# encoding=utf-8
2020-04-26 11:25:53 +00:00
import io
from rich.console import Console
2020-07-16 16:24:16 +00:00
from .render import replace_link_ids
2020-04-26 11:25:53 +00:00
2020-04-26 11:54:51 +00:00
test_data = [1, 2, 3]
2020-04-26 11:25:53 +00:00
def render_log():
console = Console(
2020-04-26 11:43:50 +00:00
file=io.StringIO(),
width=80,
force_terminal=True,
log_time_format="[TIME]",
2020-04-26 11:43:50 +00:00
color_system="truecolor",
2020-06-20 17:39:00 +00:00
legacy_windows=False,
2020-04-26 11:25:53 +00:00
)
console.log()
console.log("Hello from", console, "!")
console.log(test_data, log_locals=True)
2020-06-15 10:51:52 +00:00
return replace_link_ids(console.file.getvalue())
2020-04-26 11:25:53 +00:00
def test_log():
2020-07-27 16:21:03 +00:00
expected = "\n\x1b[2;36m[TIME]\x1b[0m\x1b[2;36m \x1b[0mHello from \x1b[1m<\x1b[0m\x1b[1;95mconsole\x1b[0m\x1b[39m \x1b[0m\x1b[3;33mwidth\x1b[0m\x1b[39m=\x1b[0m\x1b[1;34m80\x1b[0m\x1b[39m ColorSystem.TRUECOLOR\x1b[0m\x1b[1m>\x1b[0m ! \x1b]8;id=0;foo\x1b\\\x1b[2mtest_log.py\x1b[0m\x1b]8;;\x1b\\\x1b[2m:24\x1b[0m\n\x1b[2;36m \x1b[0m\x1b[2;36m \x1b[0m\x1b[1m[\x1b[0m\x1b[1;34m1\x1b[0m, \x1b[1;34m2\x1b[0m, \x1b[1;34m3\x1b[0m\x1b[1m]\x1b[0m \x1b]8;id=0;foo\x1b\\\x1b[2mtest_log.py\x1b[0m\x1b]8;;\x1b\\\x1b[2m:25\x1b[0m\n \x1b[34m╭─\x1b[0m\x1b[34m───────────────────── \x1b[0m\x1b[3;34mlocals\x1b[0m\x1b[34m ─────────────────────\x1b[0m\x1b[34m─╮\x1b[0m \n \x1b[34m│\x1b[0m \x1b[3;33mconsole\x1b[0m\x1b[31m =\x1b[0m \x1b[1m<\x1b[0m\x1b[1;95mconsole\x1b[0m\x1b[39m \x1b[0m\x1b[3;33mwidth\x1b[0m\x1b[39m=\x1b[0m\x1b[1;34m80\x1b[0m\x1b[39m ColorSystem.TRUECOLOR\x1b[0m\x1b[1m>\x1b[0m \x1b[34m│\x1b[0m \n \x1b[34m╰────────────────────────────────────────────────────╯\x1b[0m \n"
2020-04-26 11:25:53 +00:00
assert render_log() == expected
if __name__ == "__main__":
2020-06-06 11:08:07 +00:00
render = render_log()
print(render)
print(repr(render))