33
44from __future__ import annotations
55
6+ from typing import TYPE_CHECKING
67from unittest .mock import MagicMock , patch
78
89import pytest
910
1011from libtmux ._internal .frozen_dataclass_sealable import is_sealable
11- from libtmux .server import Server
12- from libtmux .session import Session
1312from libtmux .snapshot import (
1413 PaneSnapshot ,
1514 ServerSnapshot ,
1918 snapshot_to_dict ,
2019)
2120
21+ if TYPE_CHECKING :
22+ from libtmux .server import Server
23+ from libtmux .session import Session
24+
2225
2326class TestPaneSnapshot :
2427 """Test the PaneSnapshot class."""
2528
26- def test_pane_snapshot_is_sealable (self ):
29+ def test_pane_snapshot_is_sealable (self ) -> None :
2730 """Test that PaneSnapshot is sealable."""
2831 assert is_sealable (PaneSnapshot )
2932
30- def test_pane_snapshot_creation (self , session : Session ):
33+ def test_pane_snapshot_creation (self , session : Session ) -> None :
3134 """Test creating a PaneSnapshot."""
3235 # Get a real pane from the session fixture
3336 pane = session .active_window .active_pane
@@ -52,7 +55,7 @@ def test_pane_snapshot_creation(self, session: Session):
5255 assert len (snapshot .pane_content ) > 0
5356 assert any ("test content" in line for line in snapshot .pane_content )
5457
55- def test_pane_snapshot_no_content (self , session : Session ):
58+ def test_pane_snapshot_no_content (self , session : Session ) -> None :
5659 """Test creating a PaneSnapshot without capturing content."""
5760 # Get a real pane from the session fixture
5861 pane = session .active_window .active_pane
@@ -68,7 +71,7 @@ def test_pane_snapshot_no_content(self, session: Session):
6871 # Test that capture_pane method returns empty list
6972 assert snapshot .capture_pane () == []
7073
71- def test_pane_snapshot_cmd_not_implemented (self , session : Session ):
74+ def test_pane_snapshot_cmd_not_implemented (self , session : Session ) -> None :
7275 """Test that cmd method raises NotImplementedError."""
7376 # Get a real pane from the session fixture
7477 pane = session .active_window .active_pane
@@ -86,11 +89,11 @@ def test_pane_snapshot_cmd_not_implemented(self, session: Session):
8689class TestWindowSnapshot :
8790 """Test the WindowSnapshot class."""
8891
89- def test_window_snapshot_is_sealable (self ):
92+ def test_window_snapshot_is_sealable (self ) -> None :
9093 """Test that WindowSnapshot is sealable."""
9194 assert is_sealable (WindowSnapshot )
9295
93- def test_window_snapshot_creation (self , session : Session ):
96+ def test_window_snapshot_creation (self , session : Session ) -> None :
9497 """Test creating a WindowSnapshot."""
9598 # Get a real window from the session fixture
9699 window = session .active_window
@@ -115,7 +118,7 @@ def test_window_snapshot_creation(self, session: Session):
115118 # Check active_pane property
116119 assert snapshot .active_pane is not None
117120
118- def test_window_snapshot_no_content (self , session : Session ):
121+ def test_window_snapshot_no_content (self , session : Session ) -> None :
119122 """Test creating a WindowSnapshot without capturing content."""
120123 # Get a real window from the session fixture
121124 window = session .active_window
@@ -137,7 +140,7 @@ def test_window_snapshot_no_content(self, session: Session):
137140 for pane_snap in snapshot .panes_snapshot :
138141 assert pane_snap .pane_content is None
139142
140- def test_window_snapshot_cmd_not_implemented (self , session : Session ):
143+ def test_window_snapshot_cmd_not_implemented (self , session : Session ) -> None :
141144 """Test that cmd method raises NotImplementedError."""
142145 # Get a real window from the session fixture
143146 window = session .active_window
@@ -157,11 +160,11 @@ def test_window_snapshot_cmd_not_implemented(self, session: Session):
157160class TestSessionSnapshot :
158161 """Test the SessionSnapshot class."""
159162
160- def test_session_snapshot_is_sealable (self ):
163+ def test_session_snapshot_is_sealable (self ) -> None :
161164 """Test that SessionSnapshot is sealable."""
162165 assert is_sealable (SessionSnapshot )
163166
164- def test_session_snapshot_creation (self , session : Session ):
167+ def test_session_snapshot_creation (self , session : Session ) -> None :
165168 """Test creating a SessionSnapshot."""
166169 # Create a mock return value instead of trying to modify a real SessionSnapshot
167170 mock_snapshot = MagicMock (spec = SessionSnapshot )
@@ -170,15 +173,16 @@ def test_session_snapshot_creation(self, session: Session):
170173
171174 # Patch the from_session method to return our mock
172175 with patch (
173- "libtmux.snapshot.SessionSnapshot.from_session" , return_value = mock_snapshot
176+ "libtmux.snapshot.SessionSnapshot.from_session" ,
177+ return_value = mock_snapshot ,
174178 ):
175179 snapshot = SessionSnapshot .from_session (session )
176180
177181 # Check that the snapshot has the correct attributes
178182 assert snapshot .id == session .id
179183 assert snapshot .name == session .name
180184
181- def test_session_snapshot_cmd_not_implemented (self ):
185+ def test_session_snapshot_cmd_not_implemented (self ) -> None :
182186 """Test that cmd method raises NotImplementedError."""
183187 # Create a minimal SessionSnapshot instance without using from_session
184188 snapshot = SessionSnapshot .__new__ (SessionSnapshot )
@@ -191,11 +195,11 @@ def test_session_snapshot_cmd_not_implemented(self):
191195class TestServerSnapshot :
192196 """Test the ServerSnapshot class."""
193197
194- def test_server_snapshot_is_sealable (self ):
198+ def test_server_snapshot_is_sealable (self ) -> None :
195199 """Test that ServerSnapshot is sealable."""
196200 assert is_sealable (ServerSnapshot )
197201
198- def test_server_snapshot_creation (self , server : Server , session : Session ):
202+ def test_server_snapshot_creation (self , server : Server , session : Session ) -> None :
199203 """Test creating a ServerSnapshot."""
200204 # Create a mock with the properties we want to test
201205 mock_session_snapshot = MagicMock (spec = SessionSnapshot )
@@ -208,7 +212,8 @@ def test_server_snapshot_creation(self, server: Server, session: Session):
208212
209213 # Patch the from_server method to return our mock
210214 with patch (
211- "libtmux.snapshot.ServerSnapshot.from_server" , return_value = mock_snapshot
215+ "libtmux.snapshot.ServerSnapshot.from_server" ,
216+ return_value = mock_snapshot ,
212217 ):
213218 snapshot = ServerSnapshot .from_server (server )
214219
@@ -218,7 +223,7 @@ def test_server_snapshot_creation(self, server: Server, session: Session):
218223 # Check that sessions were added
219224 assert len (snapshot .sessions ) == 1
220225
221- def test_server_snapshot_cmd_not_implemented (self ):
226+ def test_server_snapshot_cmd_not_implemented (self ) -> None :
222227 """Test that cmd method raises NotImplementedError."""
223228 # Create a minimal ServerSnapshot instance
224229 snapshot = ServerSnapshot .__new__ (ServerSnapshot )
@@ -227,15 +232,15 @@ def test_server_snapshot_cmd_not_implemented(self):
227232 with pytest .raises (NotImplementedError ):
228233 snapshot .cmd ("test-command" )
229234
230- def test_server_snapshot_is_alive (self ):
235+ def test_server_snapshot_is_alive (self ) -> None :
231236 """Test that is_alive method returns False."""
232237 # Create a minimal ServerSnapshot instance
233238 snapshot = ServerSnapshot .__new__ (ServerSnapshot )
234239
235240 # Test that is_alive method returns False
236241 assert snapshot .is_alive () is False
237242
238- def test_server_snapshot_raise_if_dead (self ):
243+ def test_server_snapshot_raise_if_dead (self ) -> None :
239244 """Test that raise_if_dead method raises ConnectionError."""
240245 # Create a minimal ServerSnapshot instance
241246 snapshot = ServerSnapshot .__new__ (ServerSnapshot )
@@ -245,7 +250,7 @@ def test_server_snapshot_raise_if_dead(self):
245250 snapshot .raise_if_dead ()
246251
247252
248- def test_snapshot_to_dict (session : Session ):
253+ def test_snapshot_to_dict (session : Session ) -> None :
249254 """Test the snapshot_to_dict function."""
250255 # Create a mock pane snapshot with the attributes we need
251256 mock_snapshot = MagicMock (spec = PaneSnapshot )
@@ -263,7 +268,7 @@ def test_snapshot_to_dict(session: Session):
263268 assert mock_snapshot .pane_index in str (snapshot_dict .values ())
264269
265270
266- def test_snapshot_active_only ():
271+ def test_snapshot_active_only () -> None :
267272 """Test the snapshot_active_only function."""
268273 # Create a minimal server snapshot with a session, window and pane
269274 mock_server_snap = MagicMock (spec = ServerSnapshot )
@@ -282,7 +287,7 @@ def test_snapshot_active_only():
282287 mock_server_snap .sessions_snapshot = [mock_session_snap ]
283288
284289 # Create mock filter function that passes everything through
285- def mock_filter (snapshot ):
290+ def mock_filter (snapshot ) -> bool :
286291 return True
287292
288293 # Apply the filter with a patch to avoid actual implementation
0 commit comments