Skip to content

Commit b191a21

Browse files
committed
tests: Add tests for context manager
1 parent 6e94d38 commit b191a21

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

tests/test_pane.py

+13
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,16 @@ def test_split_pane_size(session: Session) -> None:
322322

323323
new_pane = new_pane.split(direction=PaneDirection.Right, size="10%")
324324
assert new_pane.pane_width == str(int(window_width_before * 0.1))
325+
326+
327+
def test_pane_context_manager(session: Session) -> None:
328+
"""Test Pane context manager functionality."""
329+
window = session.new_window()
330+
with window.split() as pane:
331+
pane.send_keys('echo "Hello"')
332+
assert pane in window.panes
333+
assert len(window.panes) == 2 # Initial pane + new pane
334+
335+
# Pane should be killed after exiting context
336+
assert pane not in window.panes
337+
assert len(window.panes) == 1 # Only initial pane remains

tests/test_server.py

+12
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,15 @@ def socket_name_factory() -> str:
296296
myserver.kill()
297297
if myserver2.is_alive():
298298
myserver2.kill()
299+
300+
301+
def test_server_context_manager(TempServer: type[Server]) -> None:
302+
"""Test Server context manager functionality."""
303+
with TempServer() as server:
304+
session = server.new_session()
305+
assert server.is_alive()
306+
assert len(server.sessions) == 1
307+
assert session in server.sessions
308+
309+
# Server should be killed after exiting context
310+
assert not server.is_alive()

tests/test_session.py

+12
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,15 @@ def test_session_new_window_with_direction_logs_warning_for_old_tmux(
381381
assert any("Direction flag ignored" in record.msg for record in caplog.records), (
382382
"Warning missing"
383383
)
384+
385+
386+
def test_session_context_manager(server: Server) -> None:
387+
"""Test Session context manager functionality."""
388+
with server.new_session() as session:
389+
window = session.new_window()
390+
assert session in server.sessions
391+
assert window in session.windows
392+
assert len(session.windows) == 2 # Initial window + new window
393+
394+
# Session should be killed after exiting context
395+
assert session not in server.sessions

tests/test_window.py

+12
Original file line numberDiff line numberDiff line change
@@ -603,3 +603,15 @@ def test_new_window_with_direction_logs_warning_for_old_tmux(
603603
assert any("Direction flag ignored" in record.msg for record in caplog.records), (
604604
"Warning missing"
605605
)
606+
607+
608+
def test_window_context_manager(session: Session) -> None:
609+
"""Test Window context manager functionality."""
610+
with session.new_window() as window:
611+
pane = window.split()
612+
assert window in session.windows
613+
assert pane in window.panes
614+
assert len(window.panes) == 2 # Initial pane + new pane
615+
616+
# Window should be killed after exiting context
617+
assert window not in session.windows

0 commit comments

Comments
 (0)