Skip to content

Commit e6b1384

Browse files
committed
move libtmux.test helpers to numpy style
1 parent e140cd3 commit e6b1384

File tree

1 file changed

+117
-55
lines changed

1 file changed

+117
-55
lines changed

libtmux/test.py

+117-55
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,48 @@
2121

2222

2323
def retry(seconds=RETRY_TIMEOUT_SECONDS):
24-
"""Retry a block of code until a time limit or ``break``.
25-
26-
.. code-block:: python
27-
28-
while retry():
29-
p = w.attached_pane
30-
p.server._update_panes()
31-
if p.current_path == pane_path:
32-
break
33-
34-
35-
:param seconds: Seconds to retry, defaults to ``RETRY_TIMEOUT_SECONDS``,
36-
which is configurable via environmental variables.
37-
:type seconds: int
38-
:rtype: void
24+
"""
25+
Retry a block of code until a time limit or ``break``.
26+
27+
Parameters
28+
----------
29+
seconds : int
30+
Seconds to retry, defaults to ``RETRY_TIMEOUT_SECONDS``, which is
31+
configurable via environmental variables.
32+
33+
Returns
34+
-------
35+
bool
36+
True if time passed since retry() invoked less than seconds param.
37+
38+
Examples
39+
--------
40+
41+
>>> while retry():
42+
... p = w.attached_pane
43+
... p.server._update_panes()
44+
... if p.current_path == pane_path:
45+
... break
3946
"""
4047
return (lambda: time.time() < time.time() + seconds)()
4148

4249

4350
def get_test_session_name(server, prefix=TEST_SESSION_PREFIX):
44-
"""Faker to create a session name that doesn't exist.
45-
46-
:param server: libtmux server
47-
:type server: :class:`libtmux.Server`
48-
:param prefix: prefix for sessions (e.g. libtmux_). Defaults to
51+
"""
52+
Faker to create a session name that doesn't exist.
53+
54+
Parameters
55+
----------
56+
server : :class:`libtmux.Server`
57+
libtmux server
58+
prefix : str
59+
prefix for sessions (e.g. libtmux_). Defaults to
4960
``TEST_SESSION_PREFIX``.
50-
:type prefix: string
51-
:rtype: string
52-
:returns: Random session name guaranteed to not collide with current ones
61+
62+
Returns
63+
-------
64+
str
65+
Random session name guaranteed to not collide with current ones.
5366
"""
5467
while True:
5568
session_name = prefix + next(namer)
@@ -59,15 +72,23 @@ def get_test_session_name(server, prefix=TEST_SESSION_PREFIX):
5972

6073

6174
def get_test_window_name(session, prefix=TEST_SESSION_PREFIX):
62-
"""Faker to create a window name that doesn't exist.
63-
64-
:param session: libtmux session
65-
:type session: :class:`libtmux.Session`
66-
:param prefix: prefix for sessions (e.g. libtmux_). Defaults to
67-
``TEST_SESSION_PREFIX``. ATM we reuse the test session prefix here.
68-
:type prefix: string
69-
:rtype: string
70-
:returns: Random window name guaranteed to not collide with current ones
75+
"""
76+
Faker to create a window name that doesn't exist.
77+
78+
Parameters
79+
----------
80+
session : :class:`libtmux.Session`
81+
libtmux session
82+
prefix : str
83+
prefix for windows (e.g. libtmux_). Defaults to
84+
``TEST_SESSION_PREFIX``.
85+
86+
ATM we reuse the test session prefix here.
87+
88+
Returns
89+
-------
90+
str
91+
Random window name guaranteed to not collide with current ones.
7192
"""
7293
while True:
7394
window_name = prefix + next(namer)
@@ -78,22 +99,36 @@ def get_test_window_name(session, prefix=TEST_SESSION_PREFIX):
7899

79100
@contextlib.contextmanager
80101
def temp_session(server, *args, **kwargs):
81-
"""Return a context manager with a temporary session.
82-
83-
e.g.::
102+
"""
103+
Return a context manager with a temporary session.
84104
85-
with temp_session(server) as session:
86-
session.new_window(window_name='my window')
105+
If no ``session_name`` is entered, :func:`get_test_session_name` will make
106+
an unused session name.
87107
88108
The session will destroy itself upon closing with :meth:`Session.
89109
kill_session()`.
90110
91-
If no ``session_name`` is entered, :func:`get_test_session_name` will make
92-
an unused session name.
111+
Parameters
112+
----------
113+
server : :class:`libtmux.Server`
114+
115+
Other Parameters
116+
----------------
117+
args : list
118+
Arguments passed into :meth:`Server.new_session`
119+
kwargs : dict
120+
Keyword arguments passed into :meth:`Server.new_session`
121+
122+
Yields
123+
------
124+
:class:`libtmux.Session`
125+
Temporary session
126+
127+
Examples
128+
--------
93129
94-
:args: Same arguments as :meth:`Server.new_session`
95-
:yields: Temporary session
96-
:rtype: :class:`Session`
130+
>>> with temp_session(server) as session:
131+
... session.new_window(window_name='my window')
97132
"""
98133

99134
if 'session_name' in kwargs:
@@ -113,22 +148,36 @@ def temp_session(server, *args, **kwargs):
113148

114149
@contextlib.contextmanager
115150
def temp_window(session, *args, **kwargs):
116-
"""Return a context manager with a temporary window.
117-
118-
e.g.::
119-
120-
with temp_window(session) as window:
121-
my_pane = window.split_window()
151+
"""
152+
Return a context manager with a temporary window.
122153
123154
The window will destroy itself upon closing with :meth:`window.
124155
kill_window()`.
125156
126157
If no ``window_name`` is entered, :func:`get_test_window_name` will make
127158
an unused window name.
128159
129-
:args: Same arguments as :meth:`Session.new_window`
130-
:yields: Temporary window
131-
:rtype: :class:`Window`
160+
Parameters
161+
----------
162+
session : :class:`libtmux.Session`
163+
164+
Other Parameters
165+
----------------
166+
args : list
167+
Arguments passed into :meth:`Session.new_window`
168+
kwargs : dict
169+
Keyword arguments passed into :meth:`Session.new_window`
170+
171+
Yields
172+
------
173+
:class:`libtmux.Window`
174+
temporary window
175+
176+
Examples
177+
--------
178+
179+
>>> with temp_window(session) as window:
180+
... my_pane = window.split_window()
132181
"""
133182

134183
if 'window_name' not in kwargs:
@@ -151,10 +200,23 @@ def temp_window(session, *args, **kwargs):
151200

152201
class EnvironmentVarGuard(object):
153202

154-
"""Class to help protect the environment variable properly. Can be used as
155-
a context manager.
156-
Vendorize to fix issue with Anaconda Python 2 not
157-
including test module, see #121.
203+
"""Mock environmental variables safetly.
204+
205+
Helps rotect the environment variable properly. Can be used as context
206+
manager.
207+
208+
Notes
209+
-----
210+
211+
Vendorized to fix issue with Anaconda Python 2 not including test module,
212+
see #121 [1]_
213+
214+
References
215+
----------
216+
217+
.. [1] Just installed, "ImportError: cannot import name test_support".
218+
GitHub issue for tmuxp. https://github.com/tmux-python/tmuxp/issues/121.
219+
Created October 12th, 2015. Accessed April 7th, 2018.
158220
"""
159221

160222
def __init__(self):

0 commit comments

Comments
 (0)