@@ -59,83 +59,29 @@ This page covers advanced testing techniques using the libtmux pytest plugin for
59
59
:pyobject: set_home
60
60
```
61
61
62
- ## Testing Across tmux Server Restarts
63
-
64
- For testing functionality that needs to persist across server restarts:
65
-
66
- ``` python
67
- def test_persist_across_restart (session ):
68
- """ Test functionality across server restarts."""
69
- # Set up initial state
70
- window = session.new_window(window_name = " persist-test" )
71
- pane = window.active_pane
72
- pane.send_keys(" echo 'Data to persist' > /tmp/test-data.txt" , enter = True )
73
- time.sleep(0.5 )
74
-
75
- # Get server info for reconnecting
76
- socket_path = session.server.socket_path
77
- session_id = session.id
78
-
79
- # Kill the server
80
- session.server.kill_server()
81
-
82
- # Create a new server with the same socket
83
- new_server = libtmux.Server(socket_path = socket_path)
84
- new_server.new_session(session_name = " restart-test" )
85
-
86
- # Verify data persisted
87
- new_session = new_server.get_by_id(session_id)
88
- assert new_session is None # Old session should not exist
89
-
90
- # But our file should still exist
91
- new_pane = new_server.sessions[0 ].attached_window.active_pane
92
- new_pane.send_keys(" cat /tmp/test-data.txt" , enter = True )
93
- time.sleep(0.5 )
94
-
95
- output = new_pane.capture_pane()
96
- assert any (" Data to persist" in line for line in output)
97
-
98
- # Clean up
99
- new_pane.send_keys(" rm /tmp/test-data.txt" , enter = True )
100
- ```
101
-
102
62
## Testing with Complex Layouts
103
63
104
64
Creating and testing more complex window layouts:
105
65
106
- ``` python
107
- def test_complex_layouts (session ):
108
- """ Test creating and interacting with complex window layouts."""
109
- # Create a window with multiple panes in a specific layout
110
- window = session.new_window(window_name = " complex-layout" )
111
-
112
- # Start with a simple pane
113
- main_pane = window.active_pane
114
-
115
- # Split into a left pane and right column
116
- left_pane = main_pane
117
- right_top = window.split(direction = " right" , percent = 50 )
118
-
119
- # Split the right column into top and bottom
120
- right_bottom = right_top.split(direction = " below" , percent = 50 )
121
-
122
- # Apply a layout
123
- window.select_layout(" main-vertical" )
124
-
125
- # Verify the layout was applied
126
- assert window.get(" window_layout" ) != None
127
-
128
- # Send unique commands to each pane for identification
129
- left_pane.send_keys(" echo 'Left Pane'" , enter = True )
130
- right_top.send_keys(" echo 'Right Top'" , enter = True )
131
- right_bottom.send_keys(" echo 'Right Bottom'" , enter = True )
132
-
133
- time.sleep(0.5 )
134
-
135
- # Verify each pane has the correct content
136
- assert any (" Left Pane" in line for line in left_pane.capture_pane())
137
- assert any (" Right Top" in line for line in right_top.capture_pane())
138
- assert any (" Right Bottom" in line for line in right_bottom.capture_pane())
66
+ ``` {literalinclude} ../../tests/pytest_examples/test_complex_layouts.py
67
+ :language: python
68
+ :pyobject: test_complex_layouts
69
+ ```
70
+
71
+ For an even more advanced layout, you can create a tiled configuration:
72
+
73
+ ``` {literalinclude} ../../tests/pytest_examples/test_complex_layouts.py
74
+ :language: python
75
+ :pyobject: test_tiled_layout
76
+ ```
77
+
78
+ ## Testing Across Server Restarts
79
+
80
+ When you need to test functionality that persists across server restarts:
81
+
82
+ ``` {literalinclude} ../../tests/pytest_examples/test_server_restart.py
83
+ :language: python
84
+ :pyobject: test_persist_across_restart
139
85
```
140
86
141
87
## Best Practices
0 commit comments