Skip to content

Commit 4fd24cb

Browse files
committed
!squash test_direct_testserver
1 parent 3ef9559 commit 4fd24cb

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

tests/pytest_examples/test_direct_testserver.py

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,68 @@
22

33
from __future__ import annotations
44

5+
from typing import Any, Dict
6+
57
import pytest
8+
from _pytest.fixtures import FixtureRequest
69

10+
from libtmux import Server
711
from libtmux.pytest_plugin import TestServer
812

913

1014
@pytest.fixture
11-
def custom_config(request):
12-
"""Fixture providing custom configuration settings."""
15+
def custom_config(request: FixtureRequest) -> Dict[str, Any]:
16+
"""Fixture providing custom configuration settings.
17+
18+
Returns:
19+
Dict[str, Any]: Configuration dictionary with tmux settings
20+
"""
1321
return {
1422
"colors": 256,
1523
"default-terminal": "screen-256color",
1624
"history-limit": 5000,
1725
}
1826

1927

20-
def test_custom_server_config(custom_server) -> None:
28+
def test_custom_server_config(custom_server: Server) -> None:
2129
"""Test a server with custom configuration."""
2230
# Verify server is running
2331
assert custom_server.is_alive()
2432

2533
# Verify custom socket name
26-
assert "custom-socket" in custom_server.socket_path
34+
assert "custom-socket" in str(custom_server.socket_path or "")
2735

2836
# Create a session
2937
session = custom_server.new_session(session_name="custom-test")
3038
assert session.name == "custom-test"
3139

3240
# Get color configuration
33-
colors = session.server.show_option("default-terminal")
41+
colors = custom_server.cmd("show-option", "-g", "default-terminal").stdout
3442
assert colors is not None
3543

3644

37-
def test_testserver_direct_usage() -> None:
38-
"""Test using TestServer directly as a context manager."""
39-
with TestServer() as server:
40-
# Create a session
41-
session = server.new_session(session_name="direct-test")
42-
assert session.name == "direct-test"
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"
4357

44-
# Create multiple windows
45-
windows = []
46-
for i in range(3):
47-
window = session.new_window(window_name=f"window-{i}")
48-
windows.append(window)
58+
# Create multiple windows
59+
windows = []
60+
for i in range(3):
61+
window = session.new_window(window_name=f"window-{i}")
62+
windows.append(window)
4963

50-
# Verify windows were created
51-
assert len(session.windows) >= 3
52-
for i, window in enumerate(windows):
53-
assert f"window-{i}" == window.window_name
64+
# Verify windows were created
65+
assert len(session.windows) >= 3
66+
for i, window in enumerate(windows):
67+
assert f"window-{i}" == window.window_name
5468

55-
# Server is automatically cleaned up outside the context
69+
# Server is automatically cleaned up by pytest

0 commit comments

Comments
 (0)