Skip to content

Commit e345a21

Browse files
committed
test: improve temporary context handling tests
- Add test_temp_session_outside_context to test handling of manually killed sessions - Add test_temp_window_outside_context to verify cleanup behavior for windows - Improve comments and assertions for better test clarity - Fix formatting and line length issues test: remove mocked session test in favor of real implementation
1 parent 1e31d9e commit e345a21

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/test/test_temporary.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,43 @@ def test_temp_window_cleanup_on_exception(session: Session) -> None:
9494
assert len(session.windows) == initial_windows
9595
assert window_id is not None
9696
assert not any(w.window_id == window_id for w in session.windows)
97+
98+
99+
def test_temp_session_outside_context(server: Server) -> None:
100+
"""Test that temp_session's finally block handles a session already killed."""
101+
session_name = None
102+
103+
with temp_session(server) as session:
104+
session_name = session.session_name
105+
assert session_name is not None
106+
assert server.has_session(session_name)
107+
108+
# Kill the session while inside the context
109+
session.kill()
110+
assert not server.has_session(session_name)
111+
112+
# The temp_session's finally block should handle gracefully
113+
# that the session is already gone
114+
assert session_name is not None
115+
assert not server.has_session(session_name)
116+
117+
118+
def test_temp_window_outside_context(session: Session) -> None:
119+
"""Test that temp_window's finally block handles a window already killed."""
120+
initial_windows = len(session.windows)
121+
window_id = None
122+
123+
with temp_window(session) as window:
124+
window_id = window.window_id
125+
assert window_id is not None
126+
assert len(session.windows) == initial_windows + 1
127+
128+
# Kill the window inside the context
129+
window.kill()
130+
assert len(session.windows) == initial_windows
131+
132+
# The temp_window's finally block should handle gracefully
133+
# that the window is already gone
134+
assert window_id is not None
135+
assert len(session.windows) == initial_windows
136+
assert not any(w.window_id == window_id for w in session.windows)

0 commit comments

Comments
 (0)