rich/tests/test_log.py

33 lines
1.8 KiB
Python
Raw Normal View History

2020-04-26 11:25:53 +00:00
import io
from rich.console import Console
from render import render
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] ",
color_system="truecolor",
2020-04-26 11:25:53 +00:00
)
console.log()
console.log("Hello from", console, "!")
console.log(test_data, log_locals=True)
return console.file.getvalue()
def test_log():
2020-04-26 11:54:51 +00:00
expected = "\n\x1b[2;36m[TIME] \x1b[0mHello from \x1b[1m<\x1b[0m\x1b[1;38;5;13mconsole\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[2mtest_log.py:20\x1b[0m\n\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[2mtest_log.py:21\x1b[0m\n \x1b[3m Locals \x1b[0m \n \x1b[34m╭─────────┬────────────────────────────────────────╮\x1b[0m \n \x1b[34m│\x1b[0m\x1b[32m'console'\x1b[0m\x1b[34m│\x1b[0m\x1b[1m<\x1b[0m\x1b[1;38;5;13mconsole\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__":
print(render_log())
print(repr(render_log()))