Skip to content

Commit a8c082d

Browse files
committed
tests: Add doctests
1 parent bfcbfa6 commit a8c082d

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

src/libtmux/test.py

Lines changed: 31 additions & 8 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":
@@ -68,7 +78,6 @@ def retry_until(
6878
6979
Examples
7080
--------
71-
7281
>>> def fn():
7382
... p = session.attached_window.attached_pane
7483
... p.server._update_panes()
@@ -110,6 +119,15 @@ def get_test_session_name(server: "Server", prefix: str = TEST_SESSION_PREFIX) -
110119
-------
111120
str
112121
Random session name guaranteed to not collide with current ones.
122+
123+
Examples
124+
--------
125+
>>> get_test_session_name(server=server)
126+
'libtmux_...'
127+
128+
Never the same twice:
129+
>>> get_test_session_name(server=server) != get_test_session_name(server=server)
130+
True
113131
"""
114132
while True:
115133
session_name = prefix + next(namer)
@@ -138,6 +156,15 @@ def get_test_window_name(
138156
-------
139157
str
140158
Random window name guaranteed to not collide with current ones.
159+
160+
Examples
161+
--------
162+
>>> get_test_window_name(session=session)
163+
'libtmux_...'
164+
165+
Never the same twice:
166+
>>> get_test_window_name(session=session) != get_test_window_name(session=session)
167+
True
141168
"""
142169
assert prefix is not None
143170
while True:
@@ -178,10 +205,9 @@ def temp_session(
178205
179206
Examples
180207
--------
181-
182208
>>> with temp_session(server) as session:
183209
... session.new_window(window_name='my window')
184-
Window(@... ...:..., Session($... ...))
210+
Window(@3 2:my window, Session($... ...))
185211
"""
186212

187213
if "session_name" in kwargs:
@@ -233,12 +259,12 @@ def temp_window(
233259
234260
>>> with temp_window(session) as window:
235261
... window
236-
Window(@... ...:..., Session($... ...))
262+
Window(@2 2:... Session($1 libtmux_...))
237263
238264
239265
>>> with temp_window(session) as window:
240266
... window.split_window()
241-
Pane(%... Window(@... ...:..., Session($... ...)))
267+
Pane(%4 Window(@3 2:libtmux_..., Session($1 libtmux_...)))
242268
"""
243269

244270
if "window_name" not in kwargs:
@@ -262,21 +288,18 @@ def temp_window(
262288

263289

264290
class EnvironmentVarGuard:
265-
266291
"""Mock environmental variables safetly.
267292
268293
Helps rotect the environment variable properly. Can be used as context
269294
manager.
270295
271296
Notes
272297
-----
273-
274298
Vendorized to fix issue with Anaconda Python 2 not including test module,
275299
see #121 [1]_
276300
277301
References
278302
----------
279-
280303
.. [1] Just installed, "ImportError: cannot import name test_support".
281304
GitHub issue for tmuxp. https://github.com/tmux-python/tmuxp/issues/121.
282305
Created October 12th, 2015. Accessed April 7th, 2018.

0 commit comments

Comments
 (0)