Skip to content

Commit d8613b9

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

File tree

1 file changed

+116
-55
lines changed

1 file changed

+116
-55
lines changed

libtmux/test.py

+116-55
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,47 @@
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 : Random session name guaranteed to not collide with current ones.
5365
"""
5466
while True:
5567
session_name = prefix + next(namer)
@@ -59,15 +71,23 @@ def get_test_session_name(server, prefix=TEST_SESSION_PREFIX):
5971

6072

6173
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
74+
"""
75+
Faker to create a window name that doesn't exist.
76+
77+
Parameters
78+
----------
79+
session : :class:`libtmux.Session`
80+
libtmux session
81+
prefix : str
82+
prefix for windows (e.g. libtmux_). Defaults to
83+
``TEST_SESSION_PREFIX``.
84+
85+
ATM we reuse the test session prefix here.
86+
87+
Returns
88+
-------
89+
str
90+
Random window name guaranteed to not collide with current ones.
7191
"""
7292
while True:
7393
window_name = prefix + next(namer)
@@ -78,22 +98,36 @@ def get_test_window_name(session, prefix=TEST_SESSION_PREFIX):
7898

7999
@contextlib.contextmanager
80100
def temp_session(server, *args, **kwargs):
81-
"""Return a context manager with a temporary session.
82-
83-
e.g.::
101+
"""
102+
Return a context manager with a temporary session.
84103
85-
with temp_session(server) as session:
86-
session.new_window(window_name='my window')
104+
If no ``session_name`` is entered, :func:`get_test_session_name` will make
105+
an unused session name.
87106
88107
The session will destroy itself upon closing with :meth:`Session.
89108
kill_session()`.
90109
91-
If no ``session_name`` is entered, :func:`get_test_session_name` will make
92-
an unused session name.
110+
Parameters
111+
----------
112+
server : :class:`libtmux.Server`
113+
114+
Other Parameters
115+
----------------
116+
args : list
117+
Arguments passed into :meth:`Server.new_session`
118+
kwargs : dict
119+
Keyword arguments passed into :meth:`Server.new_session`
120+
121+
Yields
122+
------
123+
:class:`libtmux.Session`
124+
Temporary session
125+
126+
Examples
127+
--------
93128
94-
:args: Same arguments as :meth:`Server.new_session`
95-
:yields: Temporary session
96-
:rtype: :class:`Session`
129+
>>> with temp_session(server) as session:
130+
... session.new_window(window_name='my window')
97131
"""
98132

99133
if 'session_name' in kwargs:
@@ -113,22 +147,36 @@ def temp_session(server, *args, **kwargs):
113147

114148
@contextlib.contextmanager
115149
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()
150+
"""
151+
Return a context manager with a temporary window.
122152
123153
The window will destroy itself upon closing with :meth:`window.
124154
kill_window()`.
125155
126156
If no ``window_name`` is entered, :func:`get_test_window_name` will make
127157
an unused window name.
128158
129-
:args: Same arguments as :meth:`Session.new_window`
130-
:yields: Temporary window
131-
:rtype: :class:`Window`
159+
Parameters
160+
----------
161+
session : :class:`libtmux.Session`
162+
163+
Other Parameters
164+
----------------
165+
args : list
166+
Arguments passed into :meth:`Session.new_window`
167+
kwargs : dict
168+
Keyword arguments passed into :meth:`Session.new_window`
169+
170+
Yields
171+
------
172+
:class:`libtmux.Window`
173+
temporary window
174+
175+
Examples
176+
--------
177+
178+
>>> with temp_window(session) as window:
179+
... my_pane = window.split_window()
132180
"""
133181

134182
if 'window_name' not in kwargs:
@@ -151,10 +199,23 @@ def temp_window(session, *args, **kwargs):
151199

152200
class EnvironmentVarGuard(object):
153201

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

160221
def __init__(self):

0 commit comments

Comments
 (0)