|
| 1 | +"""Examples for working with multiple tmux servers. |
| 2 | +
|
| 3 | +This file contains examples of using the TestServer fixture to create |
| 4 | +and manage multiple independent tmux server instances. |
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import annotations |
| 8 | + |
| 9 | + |
| 10 | +def test_basic_test_server(TestServer) -> None: |
| 11 | + """Test creating and using a server via TestServer fixture.""" |
| 12 | + # TestServer returns a partial Server class that we can instantiate |
| 13 | + ServerClass = TestServer() # Get uniquely configured Server class |
| 14 | + server = ServerClass # This is already an instance, not a class |
| 15 | + |
| 16 | + server.new_session() |
| 17 | + assert server.is_alive() |
| 18 | + |
| 19 | + # Clean up is automatic at the end of the test |
| 20 | + |
| 21 | + |
| 22 | +def test_with_config(TestServer, tmp_path) -> None: |
| 23 | + """Test creating a server with custom configuration.""" |
| 24 | + # Create a custom tmux configuration in the temporary directory |
| 25 | + config_file = tmp_path / "tmux.conf" |
| 26 | + config_file.write_text("set -g status off") |
| 27 | + |
| 28 | + # Create a server using this configuration |
| 29 | + ServerClass = TestServer() |
| 30 | + # Override the server with a new one that uses our config |
| 31 | + server = type(ServerClass)(config_file=str(config_file)) |
| 32 | + |
| 33 | + # Verify the server is running |
| 34 | + assert server.is_alive() |
| 35 | + |
| 36 | + # Create a session to work with |
| 37 | + server.new_session() |
| 38 | + |
| 39 | + # Optional: Verify the configuration was applied |
| 40 | + # This would require specific tests for the status being off |
| 41 | + |
| 42 | + # Clean up is automatic at the end of the test |
| 43 | + |
| 44 | + |
| 45 | +def test_multiple_independent_servers(TestServer) -> None: |
| 46 | + """Test running multiple independent tmux servers simultaneously.""" |
| 47 | + # Create first server |
| 48 | + ServerClass1 = TestServer() |
| 49 | + server1 = ServerClass1 # This is already an instance |
| 50 | + session1 = server1.new_session(session_name="session1") |
| 51 | + |
| 52 | + # Create second server (completely independent) |
| 53 | + ServerClass2 = TestServer() |
| 54 | + server2 = ServerClass2 # This is already an instance |
| 55 | + session2 = server2.new_session(session_name="session2") |
| 56 | + |
| 57 | + # Verify both servers are running |
| 58 | + assert server1.is_alive() |
| 59 | + assert server2.is_alive() |
| 60 | + |
| 61 | + # Verify sessions exist on their respective servers only |
| 62 | + assert session1.server is server1 |
| 63 | + assert session2.server is server2 |
| 64 | + |
| 65 | + # Verify session names are independent |
| 66 | + assert session1.name == "session1" |
| 67 | + assert session2.name == "session2" |
| 68 | + |
| 69 | + # Clean up is automatic at the end of the test |
0 commit comments