3
3
4
4
from __future__ import annotations
5
5
6
+ from typing import TYPE_CHECKING
6
7
from unittest .mock import MagicMock , patch
7
8
8
9
import pytest
9
10
10
11
from libtmux ._internal .frozen_dataclass_sealable import is_sealable
11
- from libtmux .server import Server
12
- from libtmux .session import Session
13
12
from libtmux .snapshot import (
14
13
PaneSnapshot ,
15
14
ServerSnapshot ,
19
18
snapshot_to_dict ,
20
19
)
21
20
21
+ if TYPE_CHECKING :
22
+ from libtmux .server import Server
23
+ from libtmux .session import Session
24
+
22
25
23
26
class TestPaneSnapshot :
24
27
"""Test the PaneSnapshot class."""
25
28
26
- def test_pane_snapshot_is_sealable (self ):
29
+ def test_pane_snapshot_is_sealable (self ) -> None :
27
30
"""Test that PaneSnapshot is sealable."""
28
31
assert is_sealable (PaneSnapshot )
29
32
30
- def test_pane_snapshot_creation (self , session : Session ):
33
+ def test_pane_snapshot_creation (self , session : Session ) -> None :
31
34
"""Test creating a PaneSnapshot."""
32
35
# Get a real pane from the session fixture
33
36
pane = session .active_window .active_pane
@@ -52,7 +55,7 @@ def test_pane_snapshot_creation(self, session: Session):
52
55
assert len (snapshot .pane_content ) > 0
53
56
assert any ("test content" in line for line in snapshot .pane_content )
54
57
55
- def test_pane_snapshot_no_content (self , session : Session ):
58
+ def test_pane_snapshot_no_content (self , session : Session ) -> None :
56
59
"""Test creating a PaneSnapshot without capturing content."""
57
60
# Get a real pane from the session fixture
58
61
pane = session .active_window .active_pane
@@ -68,7 +71,7 @@ def test_pane_snapshot_no_content(self, session: Session):
68
71
# Test that capture_pane method returns empty list
69
72
assert snapshot .capture_pane () == []
70
73
71
- def test_pane_snapshot_cmd_not_implemented (self , session : Session ):
74
+ def test_pane_snapshot_cmd_not_implemented (self , session : Session ) -> None :
72
75
"""Test that cmd method raises NotImplementedError."""
73
76
# Get a real pane from the session fixture
74
77
pane = session .active_window .active_pane
@@ -86,11 +89,11 @@ def test_pane_snapshot_cmd_not_implemented(self, session: Session):
86
89
class TestWindowSnapshot :
87
90
"""Test the WindowSnapshot class."""
88
91
89
- def test_window_snapshot_is_sealable (self ):
92
+ def test_window_snapshot_is_sealable (self ) -> None :
90
93
"""Test that WindowSnapshot is sealable."""
91
94
assert is_sealable (WindowSnapshot )
92
95
93
- def test_window_snapshot_creation (self , session : Session ):
96
+ def test_window_snapshot_creation (self , session : Session ) -> None :
94
97
"""Test creating a WindowSnapshot."""
95
98
# Get a real window from the session fixture
96
99
window = session .active_window
@@ -115,7 +118,7 @@ def test_window_snapshot_creation(self, session: Session):
115
118
# Check active_pane property
116
119
assert snapshot .active_pane is not None
117
120
118
- def test_window_snapshot_no_content (self , session : Session ):
121
+ def test_window_snapshot_no_content (self , session : Session ) -> None :
119
122
"""Test creating a WindowSnapshot without capturing content."""
120
123
# Get a real window from the session fixture
121
124
window = session .active_window
@@ -137,7 +140,7 @@ def test_window_snapshot_no_content(self, session: Session):
137
140
for pane_snap in snapshot .panes_snapshot :
138
141
assert pane_snap .pane_content is None
139
142
140
- def test_window_snapshot_cmd_not_implemented (self , session : Session ):
143
+ def test_window_snapshot_cmd_not_implemented (self , session : Session ) -> None :
141
144
"""Test that cmd method raises NotImplementedError."""
142
145
# Get a real window from the session fixture
143
146
window = session .active_window
@@ -157,11 +160,11 @@ def test_window_snapshot_cmd_not_implemented(self, session: Session):
157
160
class TestSessionSnapshot :
158
161
"""Test the SessionSnapshot class."""
159
162
160
- def test_session_snapshot_is_sealable (self ):
163
+ def test_session_snapshot_is_sealable (self ) -> None :
161
164
"""Test that SessionSnapshot is sealable."""
162
165
assert is_sealable (SessionSnapshot )
163
166
164
- def test_session_snapshot_creation (self , session : Session ):
167
+ def test_session_snapshot_creation (self , session : Session ) -> None :
165
168
"""Test creating a SessionSnapshot."""
166
169
# Create a mock return value instead of trying to modify a real SessionSnapshot
167
170
mock_snapshot = MagicMock (spec = SessionSnapshot )
@@ -170,15 +173,16 @@ def test_session_snapshot_creation(self, session: Session):
170
173
171
174
# Patch the from_session method to return our mock
172
175
with patch (
173
- "libtmux.snapshot.SessionSnapshot.from_session" , return_value = mock_snapshot
176
+ "libtmux.snapshot.SessionSnapshot.from_session" ,
177
+ return_value = mock_snapshot ,
174
178
):
175
179
snapshot = SessionSnapshot .from_session (session )
176
180
177
181
# Check that the snapshot has the correct attributes
178
182
assert snapshot .id == session .id
179
183
assert snapshot .name == session .name
180
184
181
- def test_session_snapshot_cmd_not_implemented (self ):
185
+ def test_session_snapshot_cmd_not_implemented (self ) -> None :
182
186
"""Test that cmd method raises NotImplementedError."""
183
187
# Create a minimal SessionSnapshot instance without using from_session
184
188
snapshot = SessionSnapshot .__new__ (SessionSnapshot )
@@ -191,11 +195,11 @@ def test_session_snapshot_cmd_not_implemented(self):
191
195
class TestServerSnapshot :
192
196
"""Test the ServerSnapshot class."""
193
197
194
- def test_server_snapshot_is_sealable (self ):
198
+ def test_server_snapshot_is_sealable (self ) -> None :
195
199
"""Test that ServerSnapshot is sealable."""
196
200
assert is_sealable (ServerSnapshot )
197
201
198
- def test_server_snapshot_creation (self , server : Server , session : Session ):
202
+ def test_server_snapshot_creation (self , server : Server , session : Session ) -> None :
199
203
"""Test creating a ServerSnapshot."""
200
204
# Create a mock with the properties we want to test
201
205
mock_session_snapshot = MagicMock (spec = SessionSnapshot )
@@ -208,7 +212,8 @@ def test_server_snapshot_creation(self, server: Server, session: Session):
208
212
209
213
# Patch the from_server method to return our mock
210
214
with patch (
211
- "libtmux.snapshot.ServerSnapshot.from_server" , return_value = mock_snapshot
215
+ "libtmux.snapshot.ServerSnapshot.from_server" ,
216
+ return_value = mock_snapshot ,
212
217
):
213
218
snapshot = ServerSnapshot .from_server (server )
214
219
@@ -218,7 +223,7 @@ def test_server_snapshot_creation(self, server: Server, session: Session):
218
223
# Check that sessions were added
219
224
assert len (snapshot .sessions ) == 1
220
225
221
- def test_server_snapshot_cmd_not_implemented (self ):
226
+ def test_server_snapshot_cmd_not_implemented (self ) -> None :
222
227
"""Test that cmd method raises NotImplementedError."""
223
228
# Create a minimal ServerSnapshot instance
224
229
snapshot = ServerSnapshot .__new__ (ServerSnapshot )
@@ -227,15 +232,15 @@ def test_server_snapshot_cmd_not_implemented(self):
227
232
with pytest .raises (NotImplementedError ):
228
233
snapshot .cmd ("test-command" )
229
234
230
- def test_server_snapshot_is_alive (self ):
235
+ def test_server_snapshot_is_alive (self ) -> None :
231
236
"""Test that is_alive method returns False."""
232
237
# Create a minimal ServerSnapshot instance
233
238
snapshot = ServerSnapshot .__new__ (ServerSnapshot )
234
239
235
240
# Test that is_alive method returns False
236
241
assert snapshot .is_alive () is False
237
242
238
- def test_server_snapshot_raise_if_dead (self ):
243
+ def test_server_snapshot_raise_if_dead (self ) -> None :
239
244
"""Test that raise_if_dead method raises ConnectionError."""
240
245
# Create a minimal ServerSnapshot instance
241
246
snapshot = ServerSnapshot .__new__ (ServerSnapshot )
@@ -245,7 +250,7 @@ def test_server_snapshot_raise_if_dead(self):
245
250
snapshot .raise_if_dead ()
246
251
247
252
248
- def test_snapshot_to_dict (session : Session ):
253
+ def test_snapshot_to_dict (session : Session ) -> None :
249
254
"""Test the snapshot_to_dict function."""
250
255
# Create a mock pane snapshot with the attributes we need
251
256
mock_snapshot = MagicMock (spec = PaneSnapshot )
@@ -263,7 +268,7 @@ def test_snapshot_to_dict(session: Session):
263
268
assert mock_snapshot .pane_index in str (snapshot_dict .values ())
264
269
265
270
266
- def test_snapshot_active_only ():
271
+ def test_snapshot_active_only () -> None :
267
272
"""Test the snapshot_active_only function."""
268
273
# Create a minimal server snapshot with a session, window and pane
269
274
mock_server_snap = MagicMock (spec = ServerSnapshot )
@@ -282,7 +287,7 @@ def test_snapshot_active_only():
282
287
mock_server_snap .sessions_snapshot = [mock_session_snap ]
283
288
284
289
# Create mock filter function that passes everything through
285
- def mock_filter (snapshot ):
290
+ def mock_filter (snapshot ) -> bool :
286
291
return True
287
292
288
293
# Apply the filter with a patch to avoid actual implementation
0 commit comments