Skip to content

Commit 89d9c33

Browse files
committed
tests: Add doctests
1 parent bfcbfa6 commit 89d9c33

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/libtmux/test.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ class RandomStrSequence:
2727
def __init__(
2828
self, characters: str = "abcdefghijklmnopqrstuvwxyz0123456789_"
2929
) -> None:
30+
"""Create a random letter / number generator. 8 chars in length.
31+
32+
>>> rng = RandomStrSequence()
33+
>>> next(rng)
34+
'...'
35+
>>> len(next(rng))
36+
8
37+
>>> type(next(rng))
38+
<class 'str'>
39+
"""
3040
self.characters: str = characters
3141

3242
def __iter__(self) -> "RandomStrSequence":
@@ -110,6 +120,15 @@ def get_test_session_name(server: "Server", prefix: str = TEST_SESSION_PREFIX) -
110120
-------
111121
str
112122
Random session name guaranteed to not collide with current ones.
123+
124+
Examples
125+
--------
126+
>>> get_test_session_name(server=server)
127+
'libtmux_...'
128+
129+
Never the same twice:
130+
>>> get_test_session_name(server=server) != get_test_session_name(server=server)
131+
True
113132
"""
114133
while True:
115134
session_name = prefix + next(namer)
@@ -138,6 +157,15 @@ def get_test_window_name(
138157
-------
139158
str
140159
Random window name guaranteed to not collide with current ones.
160+
161+
Examples
162+
--------
163+
>>> get_test_window_name(session=session)
164+
'libtmux_...'
165+
166+
Never the same twice:
167+
>>> get_test_window_name(session=session) != get_test_window_name(session=session)
168+
True
141169
"""
142170
assert prefix is not None
143171
while True:
@@ -181,7 +209,7 @@ def temp_session(
181209
182210
>>> with temp_session(server) as session:
183211
... session.new_window(window_name='my window')
184-
Window(@... ...:..., Session($... ...))
212+
Window(@3 2:my window, Session($... ...))
185213
"""
186214

187215
if "session_name" in kwargs:
@@ -233,12 +261,12 @@ def temp_window(
233261
234262
>>> with temp_window(session) as window:
235263
... window
236-
Window(@... ...:..., Session($... ...))
264+
Window(@2 2:... Session($1 libtmux_...))
237265
238266
239267
>>> with temp_window(session) as window:
240268
... window.split_window()
241-
Pane(%... Window(@... ...:..., Session($... ...)))
269+
Pane(%4 Window(@3 2:libtmux_..., Session($1 libtmux_...)))
242270
"""
243271

244272
if "window_name" not in kwargs:
@@ -270,7 +298,6 @@ class EnvironmentVarGuard:
270298
271299
Notes
272300
-----
273-
274301
Vendorized to fix issue with Anaconda Python 2 not including test module,
275302
see #121 [1]_
276303

0 commit comments

Comments
 (0)