37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
"""Tests for hermes_cli.stderr_timestamp."""
|
|
|
|
import re
|
|
import sys
|
|
|
|
from hermes_cli import stderr_timestamp
|
|
|
|
|
|
def test_main_timestamps_each_stderr_line(tmp_path):
|
|
log_path = tmp_path / "gateway.error.log"
|
|
code = (
|
|
"import sys\n"
|
|
"sys.stderr.write('first failure\\n')\n"
|
|
"sys.stderr.write('second failure without newline\\n')\n"
|
|
"sys.stderr.write('2026-07-15 12:34:56,789 already timestamped')\n"
|
|
"sys.exit(7)\n"
|
|
)
|
|
|
|
rc = stderr_timestamp.main(
|
|
[
|
|
"--error-log",
|
|
str(log_path),
|
|
"--",
|
|
sys.executable,
|
|
"-c",
|
|
code,
|
|
]
|
|
)
|
|
|
|
assert rc == 7
|
|
lines = log_path.read_text(encoding="utf-8").splitlines()
|
|
timestamp = r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}"
|
|
assert len(lines) == 3
|
|
assert re.fullmatch(f"{timestamp} first failure", lines[0])
|
|
assert re.fullmatch(f"{timestamp} second failure without newline", lines[1])
|
|
assert lines[2] == "2026-07-15 12:34:56,789 already timestamped"
|