-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathtest_tracer.py
More file actions
87 lines (73 loc) · 2.12 KB
/
test_tracer.py
File metadata and controls
87 lines (73 loc) · 2.12 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import pytest
from pluggy._tracing import TagTracer
@pytest.fixture
def rootlogger() -> TagTracer:
return TagTracer()
def test_simple(rootlogger: TagTracer) -> None:
log = rootlogger.get("pytest")
log("hello")
out: list[str] = []
rootlogger.setwriter(out.append)
log("world")
assert len(out) == 1
assert out[0] == "'world' [pytest]\n"
sublog = log.get("collection")
sublog("hello")
assert out[1] == "'hello' [pytest:collection]\n"
def test_indent(rootlogger: TagTracer) -> None:
log = rootlogger.get("1")
out = []
log.root.setwriter(lambda arg: out.append(arg))
log("hello")
log.root.indent += 1
log("line1")
log("line2")
log.root.indent += 1
log("line3")
log("line4")
log.root.indent -= 1
log("line5")
log.root.indent -= 1
log("last")
assert len(out) == 7
names = [x[: x.rfind(" [")] for x in out]
assert names == [
"'hello'",
" 'line1'",
" 'line2'",
" 'line3'",
" 'line4'",
" 'line5'",
"'last'",
]
def test_readable_output_dictargs(rootlogger: TagTracer) -> None:
out = rootlogger._format_message(["test"], [1])
assert out == "1 [test]\n"
out2 = rootlogger._format_message(["test"], ["test", {"a": 1}])
assert out2 == "'test' [test]\n a: 1\n"
def test_setprocessor(rootlogger: TagTracer) -> None:
log = rootlogger.get("1")
log2 = log.get("2")
assert log2.tags == tuple("12")
out = []
rootlogger.setprocessor(tuple("12"), lambda *args: out.append(args))
log("not seen")
log2("seen")
assert len(out) == 1
tags, args = out[0]
assert "1" in tags
assert "2" in tags
assert args == ("seen",)
l2 = []
rootlogger.setprocessor("1:2", lambda *args: l2.append(args))
log2("seen")
tags, args = l2[0]
assert args == ("seen",)
def test_unicode_surrogate_handling(rootlogger: TagTracer) -> None:
out: list[str] = []
rootlogger.setwriter(out.append)
log = rootlogger.get("pytest")
s = "hello \ud800 world"
log(s)
assert len(out) == 1
assert "hello \\ud800 world" in out[0]