forked from ChelseaKR/olive-bark-logger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_log.py
More file actions
32 lines (23 loc) · 1.09 KB
/
Copy pathtest_log.py
File metadata and controls
32 lines (23 loc) · 1.09 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
"""Operator log lines: text passthrough and JSON-per-line (GAP-OBS-1)."""
from __future__ import annotations
import json
from monitor.log import emit
def test_text_mode_prints_the_message_verbatim(capsys):
emit("text", "event_detected", "event @ 5 dur 1.0s peak -20.0 dBFS", start=5.0)
assert capsys.readouterr().out == "event @ 5 dur 1.0s peak -20.0 dBFS\n"
def test_json_mode_emits_one_object_per_line_with_its_fields(capsys):
emit("json", "event_detected", "event @ 5", start=5.0, peak_level=-20.0)
record = json.loads(capsys.readouterr().out)
assert record == {
"event": "event_detected",
"message": "event @ 5",
"peak_level": -20.0,
"start": 5.0,
}
def test_json_mode_keeps_an_embedded_newline_on_a_single_line(capsys):
emit("json", "stopped", "\nStopped.")
out = capsys.readouterr().out
# Only the print's own trailing newline is a real line break; the message's
# \n is JSON-escaped, so the record stays one line for a line-based shipper.
assert out.count("\n") == 1
assert json.loads(out)["message"] == "\nStopped."