Skip to content
This repository was archived by the owner on Sep 26, 2022. It is now read-only.

Commit 57ff453

Browse files
committed
Added tests for CustomLogRenderer
1 parent ae108a1 commit 57ff453

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/common/unit/test_logger.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
import logging
3+
4+
from common.constants import LOCATOR_LEN_BYTES
5+
from common.logger import get_logger, setup_logging, CustomLogRenderer
6+
7+
8+
def test_CustomLogRenderer_with_event():
9+
event_dict = {
10+
"event": "Test",
11+
}
12+
renderer = CustomLogRenderer()
13+
assert renderer(None, None, event_dict) == "Test"
14+
15+
16+
def test_CustomLogRenderer_with_event_and_timestamp():
17+
event_dict = {
18+
"event": "Test",
19+
"timestamp": "today", # doesn't matter if it's not correct, should just copy it verbatim
20+
}
21+
renderer = CustomLogRenderer()
22+
assert renderer(None, None, event_dict) == "today Test"
23+
24+
25+
def test_CustomLogRenderer_with_event_and_timestamp_and_component():
26+
event_dict = {
27+
"component": "MyAwesomeComponent",
28+
"event": "Test",
29+
"timestamp": "today", # doesn't matter if it's not correct, should just copy it verbatim
30+
}
31+
renderer = CustomLogRenderer()
32+
assert renderer(None, None, event_dict) == "today [MyAwesomeComponent] Test"
33+
34+
35+
def test_CustomLogRenderer_with_event_and_timestamp_and_component_and_extra_keys():
36+
event_dict = {
37+
"component": "MyAwesomeComponent",
38+
"event": "Test",
39+
"timestamp": "today", # doesn't matter if it's not correct, should just copy it verbatim
40+
"key": 6,
41+
"aKeyBefore": 42, # should be rendered before "key", because it comes lexicographically before
42+
}
43+
renderer = CustomLogRenderer()
44+
assert renderer(None, None, event_dict) == "today [MyAwesomeComponent] Test\taKeyBefore=42 key=6"

0 commit comments

Comments
 (0)