Skip to content

Commit e4d09ef

Browse files
committed
docs(README) Examples
1 parent db84b74 commit e4d09ef

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

README.md

+119
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,125 @@ if not session:
111111
print(f"Connected to: {session}")
112112
```
113113

114+
## Testable Examples
115+
116+
The following examples can be run as doctests using `py.test --doctest-modules README.md`. They assume that `server`, `session`, `window`, and `pane` objects have already been created.
117+
118+
### Working with Server Objects
119+
120+
```python
121+
>>> # Verify server is running
122+
>>> server.is_alive()
123+
True
124+
125+
>>> # Check server has sessions attribute
126+
>>> hasattr(server, 'sessions')
127+
True
128+
129+
>>> # List all tmux sessions
130+
>>> isinstance(server.sessions, list)
131+
True
132+
>>> len(server.sessions) > 0
133+
True
134+
135+
>>> # At least one session should exist
136+
>>> len([s for s in server.sessions if s.session_id]) > 0
137+
True
138+
```
139+
140+
### Session Operations
141+
142+
```python
143+
>>> # Check session attributes
144+
>>> isinstance(session.session_id, str) and session.session_id.startswith('$')
145+
True
146+
147+
>>> # Verify session name exists
148+
>>> isinstance(session.session_name, str)
149+
True
150+
>>> len(session.session_name) > 0
151+
True
152+
153+
>>> # Session should have windows
154+
>>> isinstance(session.windows, list)
155+
True
156+
>>> len(session.windows) > 0
157+
True
158+
159+
>>> # Get active window
160+
>>> session.active_window is not None
161+
True
162+
```
163+
164+
### Window Management
165+
166+
```python
167+
>>> # Window has an ID
168+
>>> isinstance(window.window_id, str) and window.window_id.startswith('@')
169+
True
170+
171+
>>> # Window belongs to a session
172+
>>> hasattr(window, 'session') and window.session is not None
173+
True
174+
175+
>>> # Window has panes
176+
>>> isinstance(window.panes, list)
177+
True
178+
>>> len(window.panes) > 0
179+
True
180+
181+
>>> # Window has a name (could be empty but should be a string)
182+
>>> isinstance(window.window_name, str)
183+
True
184+
```
185+
186+
### Pane Manipulation
187+
188+
```python
189+
>>> # Pane has an ID
190+
>>> isinstance(pane.pane_id, str) and pane.pane_id.startswith('%')
191+
True
192+
193+
>>> # Pane belongs to a window
194+
>>> hasattr(pane, 'window') and pane.window is not None
195+
True
196+
197+
>>> # Test sending commands
198+
>>> pane.send_keys('echo "Hello from libtmux test"', enter=True)
199+
>>> import time
200+
>>> time.sleep(1) # Longer wait to ensure command execution
201+
>>> output = pane.capture_pane()
202+
>>> isinstance(output, list)
203+
True
204+
>>> len(output) > 0 # Should have some output
205+
True
206+
```
207+
208+
### Filtering Objects
209+
210+
```python
211+
>>> # Session windows should be filterable
212+
>>> windows = session.windows
213+
>>> isinstance(windows, list)
214+
True
215+
>>> len(windows) > 0
216+
True
217+
218+
>>> # Filter method should return a list
219+
>>> filtered_windows = session.windows.filter()
220+
>>> isinstance(filtered_windows, list)
221+
True
222+
223+
>>> # Get method should return None or an object
224+
>>> window_maybe = session.windows.get(window_id=window.window_id)
225+
>>> window_maybe is None or window_maybe.window_id == window.window_id
226+
True
227+
228+
>>> # Test basic filtering
229+
>>> all(hasattr(w, 'window_id') for w in session.windows)
230+
True
231+
```
232+
114233
## Key Features
115234

116235
### Smart Session Management

0 commit comments

Comments
 (0)