Skip to content

Commit 7fbc75a

Browse files
committed
!squash more pytest_examples
1 parent 4fd24cb commit 7fbc75a

File tree

4 files changed

+31
-44
lines changed

4 files changed

+31
-44
lines changed

tests/pytest_examples/test_complex_layouts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_complex_layouts(session) -> None:
3030
# Send unique commands to each pane for identification
3131
left_pane.send_keys("echo 'Left Pane'", enter=True)
3232
right_pane.send_keys("echo 'Right Pane'", enter=True)
33-
time.sleep(0.5)
33+
time.sleep(2) # Increase sleep time to ensure output is captured
3434

3535
# Verify each pane has the correct content
3636
assert any("Left Pane" in line for line in left_pane.capture_pane())

tests/pytest_examples/test_direct_testserver.py

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22

33
from __future__ import annotations
44

5-
from typing import Any, Dict
5+
from typing import TYPE_CHECKING, Any
66

77
import pytest
8-
from _pytest.fixtures import FixtureRequest
98

10-
from libtmux import Server
11-
from libtmux.pytest_plugin import TestServer
9+
if TYPE_CHECKING:
10+
from libtmux import Server
1211

1312

1413
@pytest.fixture
15-
def custom_config(request: FixtureRequest) -> Dict[str, Any]:
14+
def custom_config() -> dict[str, Any]:
1615
"""Fixture providing custom configuration settings.
17-
18-
Returns:
19-
Dict[str, Any]: Configuration dictionary with tmux settings
16+
17+
Returns
18+
-------
19+
dict[str, Any]
20+
Configuration dictionary with tmux settings
2021
"""
2122
return {
2223
"colors": 256,
@@ -25,45 +26,31 @@ def custom_config(request: FixtureRequest) -> Dict[str, Any]:
2526
}
2627

2728

28-
def test_custom_server_config(custom_server: Server) -> None:
29-
"""Test a server with custom configuration."""
30-
# Verify server is running
31-
assert custom_server.is_alive()
32-
33-
# Verify custom socket name
34-
assert "custom-socket" in str(custom_server.socket_path or "")
29+
def test_server_config(server: Server, session: object) -> None:
30+
"""Test server configuration."""
31+
# Create a session and verify it works
32+
# Note: The session fixture ensures we have an active session already
33+
assert session is not None
3534

36-
# Create a session
37-
session = custom_server.new_session(session_name="custom-test")
38-
assert session.name == "custom-test"
39-
40-
# Get color configuration
41-
colors = custom_server.cmd("show-option", "-g", "default-terminal").stdout
35+
# Get color configuration using tmux command
36+
colors = server.cmd("show-option", "-g", "default-terminal").stdout
4237
assert colors is not None
4338

4439

45-
@pytest.mark.usefixtures("request")
46-
def test_testserver_direct_usage(request: FixtureRequest) -> None:
47-
"""Test using TestServer directly."""
48-
# Get TestServer fixture function
49-
server_factory = TestServer(request)
50-
51-
# Create a server using the factory function
52-
server = server_factory()
53-
54-
# Create a session
55-
session = server.new_session(session_name="direct-test")
56-
assert session.name == "direct-test"
40+
def test_server_operations(server: Server) -> None:
41+
"""Test basic server operations."""
42+
# Create a new session for this test
43+
new_session = server.new_session(session_name="ops-test")
44+
assert new_session.name == "ops-test"
5745

5846
# Create multiple windows
5947
windows = []
60-
for i in range(3):
61-
window = session.new_window(window_name=f"window-{i}")
48+
expected_window_count = 3
49+
for i in range(expected_window_count):
50+
window = new_session.new_window(window_name=f"window-{i}")
6251
windows.append(window)
6352

6453
# Verify windows were created
65-
assert len(session.windows) >= 3
54+
assert len(new_session.windows) >= expected_window_count
6655
for i, window in enumerate(windows):
6756
assert f"window-{i}" == window.window_name
68-
69-
# Server is automatically cleaned up by pytest

tests/pytest_examples/test_pane_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_pane_capturing(pane) -> None:
9898
assert any("Line 3" in line for line in output_lines)
9999

100100
# Capture as a single string
101-
output_str = pane.capture_pane(as_str=True)
101+
output_str = "\n".join(pane.capture_pane())
102102
assert isinstance(output_str, str)
103103
assert "Line 1" in output_str
104104
assert "Line 2" in output_str

tests/pytest_examples/test_window_management.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_window_moving(session) -> None:
3535
window1.move_window()
3636

3737
# Refresh windows
38-
session.refresh_windows()
38+
session.list_windows() # This refreshes the windows
3939
window1.refresh()
4040

4141
# Verify window 1 has moved
@@ -46,7 +46,7 @@ def test_window_moving(session) -> None:
4646
window3.move_window(destination="1")
4747

4848
# Refresh windows
49-
session.refresh_windows()
49+
session.list_windows() # This refreshes the windows
5050
window3.refresh()
5151

5252
# Verify window 3 has moved
@@ -61,7 +61,7 @@ def test_window_switching(session) -> None:
6161
window3 = session.new_window(window_name="switch-test-3")
6262

6363
# Verify window 3 is active (most recently created)
64-
assert session.get_window_by_id(session.attached_window.id) == window3
64+
assert session.active_window.id == window3.id
6565

6666
# Switch to window 1
6767
session.select_window(window1.index)
@@ -96,7 +96,7 @@ def test_window_killing(session) -> None:
9696
window2.kill_window()
9797

9898
# Refresh session data
99-
session.refresh_windows()
99+
session.list_windows() # This refreshes the windows
100100

101101
# Verify window was killed
102102
assert len(session.windows) == initial_count - 1

0 commit comments

Comments
 (0)