-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests!: retry_until(), deprecate retry() (#372)
Fixes #368, as retry() in its current form is broke and won't work within a `with` block. The function is deprecated and will be removed in 0.13.x. 0.12.x will warn when using it. retry_until() is now available and will either raise or return False if raise=False is passed. See also: - tmux-python/tmuxp#620 - tmux-python/tmuxp#704 (comment)
- Loading branch information
Showing
5 changed files
with
168 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from time import time | ||
|
||
import pytest | ||
|
||
from libtmux.test import WaitTimeout, retry_until | ||
|
||
|
||
def test_retry_three_times(): | ||
ini = time() | ||
value = 0 | ||
|
||
def call_me_three_times(): | ||
nonlocal value | ||
|
||
if value == 2: | ||
return True | ||
|
||
value += 1 | ||
|
||
return False | ||
|
||
retry_until(call_me_three_times, 1) | ||
|
||
end = time() | ||
|
||
assert abs((end - ini) - 0.1) < 0.01 | ||
|
||
|
||
def test_function_times_out(): | ||
ini = time() | ||
|
||
def never_true(): | ||
return False | ||
|
||
with pytest.raises(WaitTimeout): | ||
retry_until(never_true, 1) | ||
|
||
end = time() | ||
|
||
assert abs((end - ini) - 1.0) < 0.01 | ||
|
||
|
||
def test_function_times_out_no_rise(): | ||
ini = time() | ||
|
||
def never_true(): | ||
return False | ||
|
||
retry_until(never_true, 1, raises=False) | ||
|
||
end = time() | ||
|
||
assert abs((end - ini) - 1.0) < 0.01 | ||
|
||
|
||
def test_function_times_out_no_raise_assert(): | ||
ini = time() | ||
|
||
def never_true(): | ||
return False | ||
|
||
assert not retry_until(never_true, 1, raises=False) | ||
|
||
end = time() | ||
|
||
assert abs((end - ini) - 1.0) < 0.01 | ||
|
||
|
||
def test_retry_three_times_no_raise_assert(): | ||
ini = time() | ||
value = 0 | ||
|
||
def call_me_three_times(): | ||
nonlocal value | ||
|
||
if value == 2: | ||
return True | ||
|
||
value += 1 | ||
|
||
return False | ||
|
||
assert retry_until(call_me_three_times, 1, raises=False) | ||
|
||
end = time() | ||
|
||
assert abs((end - ini) - 0.1) < 0.01 |