-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix retry decorator exception handling logic (#19)
* updated retry logic and added test * changed exception type to tuple * updated test * update openai_exception type * fixed test names * tuple updates * split test into two
- Loading branch information
1 parent
adf21d3
commit 1ace1f4
Showing
3 changed files
with
31 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from llm_gateway.utils import max_retries | ||
from openai.error import APIError | ||
|
||
|
||
def test_retry_decorator_mismatch_exception(): | ||
retry_mock = Mock() | ||
retry_mock.side_effect = [APIError("test"), "success"] | ||
|
||
@max_retries(1, exceptions=(ValueError,)) | ||
def mismatch_exception(): | ||
return retry_mock() | ||
|
||
with pytest.raises(APIError): | ||
mismatch_exception() | ||
|
||
|
||
def test_retry_decorator_matching_exception(): | ||
retry_mock = Mock() | ||
retry_mock.side_effect = [APIError("test"), "success"] | ||
|
||
## Matching retry exception | ||
@max_retries(1, exceptions=(APIError,)) | ||
def matching_exception(): | ||
return retry_mock() | ||
|
||
assert matching_exception() == "success" |