enhance support for precision bit in LEVELNAME_FMT_REGEX regex

This commit is contained in:
Rahul Kumaresan
2021-05-07 16:16:40 +05:30
parent 4b6188b3b1
commit 1e3fcece6d
3 changed files with 33 additions and 1 deletions

View File

@@ -36,6 +36,37 @@ def test_coloredlogformatter() -> None:
assert output == ("dummypath 10 INFO Test Message")
def test_coloredlogformatter_with_width_precision() -> None:
logfmt = "%(filename)-25s %(lineno)4d %(levelname)-8.2s %(message)s"
record = logging.LogRecord(
name="dummy",
level=logging.INFO,
pathname="dummypath",
lineno=10,
msg="Test Message",
args=(),
exc_info=None,
)
class ColorConfig:
class option:
pass
tw = TerminalWriter()
tw.hasmarkup = True
formatter = ColoredLevelFormatter(tw, logfmt)
output = formatter.format(record)
assert output == (
"dummypath 10 \x1b[32mINFO \x1b[0m Test Message"
)
tw.hasmarkup = False
formatter = ColoredLevelFormatter(tw, logfmt)
output = formatter.format(record)
assert output == ("dummypath 10 INFO Test Message")
def test_multiline_message() -> None:
from _pytest.logging import PercentStyleMultiline