Skip to content

Commit b487861

Browse files
committed
docs: update pytest-plugin docs to include new examples
1 parent 8467da2 commit b487861

File tree

3 files changed

+115
-73
lines changed

3 files changed

+115
-73
lines changed

docs/pytest-plugin/advanced-techniques.md

Lines changed: 19 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -59,83 +59,29 @@ This page covers advanced testing techniques using the libtmux pytest plugin for
5959
:pyobject: set_home
6060
```
6161

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-
10262
## Testing with Complex Layouts
10363

10464
Creating and testing more complex window layouts:
10565

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
13985
```
14086

14187
## Best Practices

docs/pytest-plugin/fixtures.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ def test_multiple_servers(TestServer):
122122
assert session2.server is server2
123123
```
124124

125+
For more advanced usage with custom configuration:
126+
127+
```{literalinclude} ../../tests/pytest_examples/test_direct_testserver.py
128+
:language: python
129+
:pyobject: test_custom_server_config
130+
```
131+
132+
You can also use TestServer directly as a context manager:
133+
134+
```{literalinclude} ../../tests/pytest_examples/test_direct_testserver.py
135+
:language: python
136+
:pyobject: test_testserver_direct_usage
137+
```
138+
125139
### Environment fixtures
126140

127141
These fixtures help manage the testing environment:

docs/pytest-plugin/usage-examples.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,88 @@ This page provides practical code examples for testing with the libtmux pytest p
108108
:pyobject: test_pane_layout
109109
```
110110

111+
## Window Management
112+
113+
Window management is a common task when working with tmux. Here are some examples:
114+
115+
### Window Renaming
116+
117+
```{literalinclude} ../../tests/pytest_examples/test_window_management.py
118+
:language: python
119+
:pyobject: test_window_renaming
120+
```
121+
122+
### Moving Windows
123+
124+
```{literalinclude} ../../tests/pytest_examples/test_window_management.py
125+
:language: python
126+
:pyobject: test_window_moving
127+
```
128+
129+
### Switching Between Windows
130+
131+
```{literalinclude} ../../tests/pytest_examples/test_window_management.py
132+
:language: python
133+
:pyobject: test_window_switching
134+
```
135+
136+
### Killing Windows
137+
138+
```{literalinclude} ../../tests/pytest_examples/test_window_management.py
139+
:language: python
140+
:pyobject: test_window_killing
141+
```
142+
143+
## Pane Operations
144+
145+
Panes are the subdivisions within windows where commands are executed:
146+
147+
### Advanced Pane Functions
148+
149+
```{literalinclude} ../../tests/pytest_examples/test_pane_operations.py
150+
:language: python
151+
:pyobject: test_pane_functions
152+
```
153+
154+
### Resizing Panes
155+
156+
```{literalinclude} ../../tests/pytest_examples/test_pane_operations.py
157+
:language: python
158+
:pyobject: test_pane_resizing
159+
```
160+
161+
### Capturing Pane Content
162+
163+
```{literalinclude} ../../tests/pytest_examples/test_pane_operations.py
164+
:language: python
165+
:pyobject: test_pane_capturing
166+
```
167+
168+
## Process Control
169+
170+
Working with processes in tmux panes:
171+
172+
### Process Detection
173+
174+
```{literalinclude} ../../tests/pytest_examples/test_process_control.py
175+
:language: python
176+
:pyobject: test_process_detection
177+
```
178+
179+
### Handling Command Output
180+
181+
```{literalinclude} ../../tests/pytest_examples/test_process_control.py
182+
:language: python
183+
:pyobject: test_command_output_scrollback
184+
```
185+
186+
### Background Processes
187+
188+
```{literalinclude} ../../tests/pytest_examples/test_process_control.py
189+
:language: python
190+
:pyobject: test_running_background_process
191+
```
192+
111193
## Custom Configuration Testing
112194

113195
### Creating a Custom Configuration

0 commit comments

Comments
 (0)