File: test_logging.py

package info (click to toggle)
python-scrapli-replay 2023.7.30-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 456 kB
  • sloc: python: 2,625; makefile: 43
file content (28 lines) | stat: -rw-r--r-- 933 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import re
from logging import LogRecord

from scrapli_replay.logging import ScrapliReplayFormatter


def test_scrapli_replay_formatter():
    formatter = ScrapliReplayFormatter(log_header=True, caller_info=True)
    record = LogRecord(
        name="test_log",
        level=20,
        pathname="somepath",
        lineno=999,
        msg="thisisalogmessage!",
        args=None,
        exc_info=None,
        func="coolfunc",
    )
    formatted_record = formatter.format(record=record)
    assert (
        re.sub(
            string=formatted_record,
            pattern=r"\d{4}-\d{2}\-\d{2} \d{2}:\d{2}:\d{2},\d{3}",
            repl="_TIMESTAMP___TIMESTAMP_",
        )
        == "ID    | TIMESTAMP               | LEVEL    | MODULE               | FUNCNAME             | LINE  | MESSAGE\n"
        "1     | _TIMESTAMP___TIMESTAMP_ | INFO     | somepath             | coolfunc             | 999   | thisisalogmessage!"
    )