-
Notifications
You must be signed in to change notification settings - Fork 110
Modify retry() to take a callable and enforce the timeout #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8fd0cee
Add exception to libtmux.exc
categulario 036642e
Add retry_until() to take a callable and enforce the timeout
categulario a8c8ca3
test(retry_until): Return truthy when True, False with timeout raise=…
tony eb9742f
tests: Test retry_until with assert statements raises=False
tony 1a37c31
chore(retry): Type annotation
tony e3194ba
chore: Add DeprecationWarning for retry()
tony be119e0
chore(retry_until): Type annotation
tony 5c98cd2
docs(API): Add retry_until
tony 8f555e5
docs(CHANGES): Note changes to retry
tony File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add retry_until() to take a callable and enforce the timeout
- Loading branch information
commit 036642ebb4aa83c560fb6ca6acc2bc870d165b53
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,53 @@ | ||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.