Skip to content

Commit c1ed962

Browse files
committed
tests(refactor[plugin_system]) Use Pane.display_message wrapper
why: Six tests in the plugin-system suite were querying tmux for session/window names via the same `session.cmd("display-message", "-p", "'#S'")` escape hatch that production just migrated away from in `cli/load.py:_reattach`. Keeping the tests on the typed wrapper that production now uses keeps the call shape consistent across the codebase and removes the last `cmd("display-message", ...)` site from the repo. what: - `tests/cli/test_cli.py::test_reattach_plugins`: replace the `cmd()` call with `active_pane.display_message("'#S'", get_text=True)` so the post-reattach assertion uses the typed wrapper. - `tests/workspace/test_builder.py`: migrate four `test_plugin_system_*` checks (`before_workspace_builder`, `on_window_create`, `after_window_finished`, and the multi-window variant covering both `before_script` and `after_window_finished`) onto `active_pane.display_message()`. The multi-window variant hoists the active_pane lookup once and reuses it for both the `'#S'` and `'#W'` queries. - Each call site adds a narrowing assert on `active_pane` (libtmux types it as `Pane | None`) so mypy can prove the call is well-typed. Mirrors the production assert added in `_reattach()`. No behavior change: tmux's `display-message` defaults to the session's active pane when no `-t` is passed, so the underlying tmux invocations are byte-for-byte identical to the prior `session.cmd(...)` calls.
1 parent 32f62cf commit c1ed962

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

‎tests/cli/test_cli.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ def test_reattach_plugins(
170170
_reattach(builder)
171171

172172
assert builder.session is not None
173-
proc = builder.session.cmd("display-message", "-p", "'#S'")
173+
active_pane = builder.session.active_pane
174+
assert active_pane is not None
175+
lines = active_pane.display_message("'#S'", get_text=True)
174176

175-
assert proc.stdout[0] == "'plugin_test_r'"
177+
assert lines[0] == "'plugin_test_r'"

‎tests/workspace/test_builder.py‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,10 @@ def test_plugin_system_before_workspace_builder(
824824

825825
builder.build(session=session)
826826

827-
proc = session.cmd("display-message", "-p", "'#S'")
828-
assert proc.stdout[0] == "'plugin_test_bwb'"
827+
active_pane = session.active_pane
828+
assert active_pane is not None
829+
lines = active_pane.display_message("'#S'", get_text=True)
830+
assert lines[0] == "'plugin_test_bwb'"
829831

830832

831833
def test_plugin_system_on_window_create(
@@ -847,8 +849,10 @@ def test_plugin_system_on_window_create(
847849

848850
builder.build(session=session)
849851

850-
proc = session.cmd("display-message", "-p", "'#W'")
851-
assert proc.stdout[0] == "'plugin_test_owc'"
852+
active_pane = session.active_pane
853+
assert active_pane is not None
854+
lines = active_pane.display_message("'#W'", get_text=True)
855+
assert lines[0] == "'plugin_test_owc'"
852856

853857

854858
def test_plugin_system_after_window_finished(
@@ -870,8 +874,10 @@ def test_plugin_system_after_window_finished(
870874

871875
builder.build(session=session)
872876

873-
proc = session.cmd("display-message", "-p", "'#W'")
874-
assert proc.stdout[0] == "'plugin_test_awf'"
877+
active_pane = session.active_pane
878+
assert active_pane is not None
879+
lines = active_pane.display_message("'#W'", get_text=True)
880+
assert lines[0] == "'plugin_test_awf'"
875881

876882

877883
def test_plugin_system_on_window_create_multiple_windows(
@@ -946,15 +952,18 @@ def test_plugin_system_multiple_plugins(
946952

947953
builder.build(session=session)
948954

955+
active_pane = session.active_pane
956+
assert active_pane is not None
957+
949958
# Drop through to the before_script plugin hook
950-
proc = session.cmd("display-message", "-p", "'#S'")
951-
assert proc.stdout[0] == "'plugin_test_bwb'"
959+
lines = active_pane.display_message("'#S'", get_text=True)
960+
assert lines[0] == "'plugin_test_bwb'"
952961

953962
# Drop through to the after_window_finished. This won't succeed
954963
# unless on_window_create succeeds because of how the test plugin
955964
# override methods are currently written
956-
proc = session.cmd("display-message", "-p", "'#W'")
957-
assert proc.stdout[0] == "'mp_test_awf'"
965+
lines = active_pane.display_message("'#W'", get_text=True)
966+
assert lines[0] == "'mp_test_awf'"
958967

959968

960969
def test_load_configs_same_session(

0 commit comments

Comments
 (0)