mirror of
https://github.com/Textualize/rich.git
synced 2025-08-31 15:37:24 +00:00
logging handler tests
This commit is contained in:
parent
83c4c9a5ce
commit
3f7466357a
3 changed files with 34 additions and 8 deletions
31
tests/test_logging.py
Normal file
31
tests/test_logging.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
import io
|
||||
import logging
|
||||
|
||||
from rich.console import Console
|
||||
from rich.logging import RichHandler
|
||||
|
||||
handler = RichHandler(
|
||||
console=Console(file=io.StringIO(), force_terminal=True, width=80)
|
||||
)
|
||||
logging.basicConfig(
|
||||
level="NOTSET", format="%(message)s", datefmt="[DATE] ", handlers=[handler]
|
||||
)
|
||||
log = logging.getLogger("rich")
|
||||
|
||||
|
||||
def make_log():
|
||||
log.debug("foo")
|
||||
render = handler.console.file.getvalue()
|
||||
return render
|
||||
|
||||
|
||||
def test_log():
|
||||
render = make_log()
|
||||
expected = "\x1b[2;36m[DATE] \x1b[0m\x1b[32mDEBUG\x1b[0m foo \x1b[2mtest_logging.py:17\x1b[0m\n"
|
||||
assert render == expected
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
render = make_log()
|
||||
print(render)
|
||||
print(repr(render))
|
Loading…
Add table
Add a link
Reference in a new issue