Skip to content

Commit c041514

Browse files
categulariotony
authored andcommitted
restore old retry() function and rename new to retry_until()
1 parent da66d2f commit c041514

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

libtmux/test.py

+28-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,34 @@
1919
fixtures_dir = os.path.realpath(os.path.join(current_dir, "fixtures"))
2020

2121

22-
def retry(
22+
def retry(seconds=RETRY_TIMEOUT_SECONDS):
23+
"""
24+
Retry a block of code until a time limit or ``break``.
25+
26+
Parameters
27+
----------
28+
seconds : int
29+
Seconds to retry, defaults to ``RETRY_TIMEOUT_SECONDS``, which is
30+
configurable via environmental variables.
31+
32+
Returns
33+
-------
34+
bool
35+
True if time passed since retry() invoked less than seconds param.
36+
37+
Examples
38+
--------
39+
40+
>>> while retry():
41+
... p = w.attached_pane
42+
... p.server._update_panes()
43+
... if p.current_path == pane_path:
44+
... break
45+
"""
46+
return (lambda: time.time() < time.time() + seconds)()
47+
48+
49+
def retry_until(
2350
fun,
2451
seconds=RETRY_TIMEOUT_SECONDS,
2552
*,
@@ -43,11 +70,6 @@ def retry(
4370
raises : bool
4471
Wether or not to raise an exception on timeout. Defaults to ``True``.
4572
46-
Returns
47-
-------
48-
bool
49-
True if time passed since retry() invoked less than seconds param.
50-
5173
Examples
5274
--------
5375

tests/test_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from time import time
22
import pytest
33

4-
from libtmux.test import retry, WaitTimeout
4+
from libtmux.test import retry_until, WaitTimeout
55

66

77
def test_retry_three_times():
@@ -18,7 +18,7 @@ def call_me_three_times():
1818

1919
return False
2020

21-
retry(call_me_three_times, 1)
21+
retry_until(call_me_three_times, 1)
2222

2323
end = time()
2424

@@ -32,7 +32,7 @@ def never_true():
3232
return False
3333

3434
with pytest.raises(WaitTimeout):
35-
retry(never_true, 1)
35+
retry_until(never_true, 1)
3636

3737
end = time()
3838

@@ -45,7 +45,7 @@ def test_function_times_out_no_rise():
4545
def never_true():
4646
return False
4747

48-
retry(never_true, 1, raises=False)
48+
retry_until(never_true, 1, raises=False)
4949

5050
end = time()
5151

0 commit comments

Comments
 (0)