|
1 | | -"""Examples for working with multiple panes in tmux tests.""" |
| 1 | +"""Example of using multiple panes in tmux tests.""" |
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import time |
6 | 6 |
|
7 | | -from libtmux.constants import PaneDirection |
8 | | - |
9 | 7 |
|
10 | 8 | def test_multi_pane_interaction(server, session) -> None: |
11 | 9 | """Test interaction between multiple panes.""" |
12 | | - # Create a window with multiple panes for testing |
| 10 | + # Create a window for testing multi-pane interactions |
13 | 11 | window = session.new_window(window_name="multi-pane-test") |
14 | 12 |
|
15 | | - # First pane (already exists as the active pane) |
| 13 | + # Initialize the main pane |
16 | 14 | main_pane = window.active_pane |
17 | 15 |
|
18 | 16 | # Create a second pane for output |
19 | | - output_pane = window.split(direction=PaneDirection.Right) |
| 17 | + output_pane = window.split_window(vertical=True) |
20 | 18 |
|
21 | 19 | # Create a third pane for monitoring |
22 | | - monitor_pane = main_pane.split(direction=PaneDirection.Below) |
| 20 | + monitor_pane = main_pane.split_window(vertical=False) |
23 | 21 |
|
24 | 22 | # Wait for panes to be ready |
25 | 23 | time.sleep(0.5) |
26 | 24 |
|
27 | | - # Set up the panes with specific content |
28 | | - main_pane.send_keys("echo 'This is the main pane'", enter=True) |
29 | | - output_pane.send_keys("echo 'This is the output pane'", enter=True) |
30 | | - monitor_pane.send_keys("echo 'This is the monitor pane'", enter=True) |
| 25 | + # Verify we have three panes |
| 26 | + assert len(window.panes) == 3 |
31 | 27 |
|
32 | | - # Create a temporary file in one pane |
33 | | - main_pane.send_keys("echo 'Shared data' > shared_file.txt", enter=True) |
| 28 | + # Send a command to the main pane |
| 29 | + main_pane.send_keys("echo 'Hello from main pane'", enter=True) |
34 | 30 | time.sleep(0.5) |
35 | 31 |
|
36 | | - # Read it from another pane |
37 | | - output_pane.send_keys("cat shared_file.txt", enter=True) |
| 32 | + # Send a command to the output pane |
| 33 | + output_pane.send_keys("echo 'Hello from output pane'", enter=True) |
38 | 34 | time.sleep(0.5) |
39 | 35 |
|
40 | | - # Verify the content was shared |
41 | | - output_content = output_pane.capture_pane() |
42 | | - assert any("Shared data" in line for line in output_content) |
43 | | - |
44 | | - # Use the monitor pane to check the file exists |
45 | | - monitor_pane.send_keys("ls -la shared_file.txt", enter=True) |
| 36 | + # Send a command to the monitor pane |
| 37 | + monitor_pane.send_keys("echo 'Hello from monitor pane'", enter=True) |
46 | 38 | time.sleep(0.5) |
47 | 39 |
|
48 | | - monitor_content = monitor_pane.capture_pane() |
49 | | - assert any("shared_file.txt" in line for line in monitor_content) |
| 40 | + # Refresh the window to get updated pane information |
| 41 | + window.refresh() |
50 | 42 |
|
51 | | - # Clean up |
52 | | - main_pane.send_keys("rm shared_file.txt", enter=True) |
| 43 | + # Verify all panes are still accessible |
| 44 | + assert main_pane.id is not None |
| 45 | + assert output_pane.id is not None |
| 46 | + assert monitor_pane.id is not None |
53 | 47 |
|
54 | 48 |
|
55 | 49 | def test_pane_layout(session) -> None: |
56 | | - """Test creating and manipulating pane layouts.""" |
| 50 | + """Test complex pane layouts.""" |
57 | 51 | # Create a window for testing layouts |
58 | 52 | window = session.new_window(window_name="layout-test") |
59 | 53 |
|
60 | | - # Initial pane |
| 54 | + # Get the initial pane |
61 | 55 | top_pane = window.active_pane |
62 | 56 |
|
63 | 57 | # Create a layout with multiple panes |
64 | | - right_pane = window.split(direction=PaneDirection.Right) |
65 | | - bottom_left = top_pane.split(direction=PaneDirection.Below) |
66 | | - bottom_right = right_pane.split(direction=PaneDirection.Below) |
| 58 | + right_pane = window.split_window(vertical=True) |
| 59 | + bottom_left = top_pane.split_window(vertical=False) |
| 60 | + bottom_right = right_pane.split_window(vertical=False) |
67 | 61 |
|
68 | 62 | # Check the number of panes |
69 | 63 | assert len(window.panes) == 4 |
70 | 64 |
|
71 | | - # Send different commands to each pane |
72 | | - top_pane.send_keys("echo 'Top left pane'", enter=True) |
73 | | - right_pane.send_keys("echo 'Top right pane'", enter=True) |
74 | | - bottom_left.send_keys("echo 'Bottom left pane'", enter=True) |
75 | | - bottom_right.send_keys("echo 'Bottom right pane'", enter=True) |
76 | | - |
77 | | - time.sleep(0.5) |
78 | | - |
79 | | - # Verify each pane has the correct content |
80 | | - assert any("Top left pane" in line for line in top_pane.capture_pane()) |
81 | | - assert any("Top right pane" in line for line in right_pane.capture_pane()) |
82 | | - assert any("Bottom left pane" in line for line in bottom_left.capture_pane()) |
83 | | - assert any("Bottom right pane" in line for line in bottom_right.capture_pane()) |
84 | | - |
85 | | - # Test selecting panes by making a string comparison |
86 | | - window.select_pane(bottom_right.pane_id) |
87 | | - assert window.active_pane.pane_id == bottom_right.pane_id |
| 65 | + # Apply the tiled layout |
| 66 | + window.select_layout("tiled") |
88 | 67 |
|
89 | | - window.select_pane(top_pane.pane_id) |
90 | | - assert window.active_pane.pane_id == top_pane.pane_id |
| 68 | + # Verify all panes are accessible |
| 69 | + assert top_pane.id is not None |
| 70 | + assert right_pane.id is not None |
| 71 | + assert bottom_left.id is not None |
| 72 | + assert bottom_right.id is not None |
0 commit comments