logging handler tests

This commit is contained in:
Will McGugan 2020-04-26 12:38:38 +01:00
parent 83c4c9a5ce
commit 3f7466357a
3 changed files with 34 additions and 8 deletions

31
tests/test_logging.py Normal file
View 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))