Skip to content

Commit 11a5d65

Browse files
committed
libtmux(test[logging]): add INFO lifecycle logging schema test
why: No test coverage existed for INFO-level lifecycle log records, leaving the str-type constraint on extra values unverified. what: - Add test_lifecycle_info_logging_schema that creates a window and asserts INFO records have str-typed extra values - Verify tmux_subcommand, tmux_session, tmux_window, tmux_target are all str when present
1 parent b55be19 commit 11a5d65

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

tests/test_logging.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
if t.TYPE_CHECKING:
1111
from libtmux.server import Server
12+
from libtmux.session import Session
1213

1314

1415
def test_tmux_cmd_debug_logging_schema(
@@ -20,6 +21,33 @@ def test_tmux_cmd_debug_logging_schema(
2021
server.cmd("list-sessions")
2122
records = [r for r in caplog.records if hasattr(r, "tmux_cmd")]
2223
assert len(records) >= 1
23-
record = records[0]
24-
assert isinstance(getattr(record, "tmux_cmd"), str)
25-
assert isinstance(getattr(record, "tmux_exit_code"), int)
24+
record = t.cast(t.Any, records[0])
25+
assert isinstance(record.tmux_cmd, str)
26+
assert isinstance(record.tmux_exit_code, int)
27+
28+
29+
def test_lifecycle_info_logging_schema(
30+
session: Session,
31+
caplog: pytest.LogCaptureFixture,
32+
) -> None:
33+
"""Test that lifecycle operations produce INFO records with str-typed extra."""
34+
with caplog.at_level(logging.INFO, logger="libtmux.session"):
35+
window = session.new_window(window_name="log_test")
36+
37+
records = [
38+
r
39+
for r in caplog.records
40+
if hasattr(r, "tmux_subcommand") and r.levelno == logging.INFO
41+
]
42+
assert len(records) >= 1, "expected at least one INFO lifecycle record"
43+
44+
for record in records:
45+
rec = t.cast(t.Any, record)
46+
for key in ("tmux_subcommand", "tmux_session", "tmux_window", "tmux_target"):
47+
val = getattr(rec, key, None)
48+
if val is not None:
49+
assert isinstance(val, str), (
50+
f"extra key {key!r} should be str, got {type(val).__name__}"
51+
)
52+
53+
window.kill()

0 commit comments

Comments
 (0)