|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +from typing import Any, Dict |
| 6 | + |
5 | 7 | import pytest |
| 8 | +from _pytest.fixtures import FixtureRequest |
6 | 9 |
|
| 10 | +from libtmux import Server |
7 | 11 | from libtmux.pytest_plugin import TestServer |
8 | 12 |
|
9 | 13 |
|
10 | 14 | @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 | + """ |
13 | 21 | return { |
14 | 22 | "colors": 256, |
15 | 23 | "default-terminal": "screen-256color", |
16 | 24 | "history-limit": 5000, |
17 | 25 | } |
18 | 26 |
|
19 | 27 |
|
20 | | -def test_custom_server_config(custom_server) -> None: |
| 28 | +def test_custom_server_config(custom_server: Server) -> None: |
21 | 29 | """Test a server with custom configuration.""" |
22 | 30 | # Verify server is running |
23 | 31 | assert custom_server.is_alive() |
24 | 32 |
|
25 | 33 | # Verify custom socket name |
26 | | - assert "custom-socket" in custom_server.socket_path |
| 34 | + assert "custom-socket" in str(custom_server.socket_path or "") |
27 | 35 |
|
28 | 36 | # Create a session |
29 | 37 | session = custom_server.new_session(session_name="custom-test") |
30 | 38 | assert session.name == "custom-test" |
31 | 39 |
|
32 | 40 | # Get color configuration |
33 | | - colors = session.server.show_option("default-terminal") |
| 41 | + colors = custom_server.cmd("show-option", "-g", "default-terminal").stdout |
34 | 42 | assert colors is not None |
35 | 43 |
|
36 | 44 |
|
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" |
43 | 57 |
|
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) |
49 | 63 |
|
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 |
54 | 68 |
|
55 | | - # Server is automatically cleaned up outside the context |
| 69 | + # Server is automatically cleaned up by pytest |
0 commit comments