21
21
22
22
23
23
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
39
46
"""
40
47
return (lambda : time .time () < time .time () + seconds )()
41
48
42
49
43
50
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
49
60
``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.
53
66
"""
54
67
while True :
55
68
session_name = prefix + next (namer )
@@ -59,15 +72,23 @@ def get_test_session_name(server, prefix=TEST_SESSION_PREFIX):
59
72
60
73
61
74
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.
71
92
"""
72
93
while True :
73
94
window_name = prefix + next (namer )
@@ -78,22 +99,36 @@ def get_test_window_name(session, prefix=TEST_SESSION_PREFIX):
78
99
79
100
@contextlib .contextmanager
80
101
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.
84
104
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.
87
107
88
108
The session will destroy itself upon closing with :meth:`Session.
89
109
kill_session()`.
90
110
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
+ --------
93
129
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')
97
132
"""
98
133
99
134
if 'session_name' in kwargs :
@@ -113,22 +148,36 @@ def temp_session(server, *args, **kwargs):
113
148
114
149
@contextlib .contextmanager
115
150
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.
122
153
123
154
The window will destroy itself upon closing with :meth:`window.
124
155
kill_window()`.
125
156
126
157
If no ``window_name`` is entered, :func:`get_test_window_name` will make
127
158
an unused window name.
128
159
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()
132
181
"""
133
182
134
183
if 'window_name' not in kwargs :
@@ -151,10 +200,23 @@ def temp_window(session, *args, **kwargs):
151
200
152
201
class EnvironmentVarGuard (object ):
153
202
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.
158
220
"""
159
221
160
222
def __init__ (self ):
0 commit comments