-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
throw error for unknown providers or moderator
- Loading branch information
1 parent
78d4913
commit 2e0e2f8
Showing
6 changed files
with
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class LoadExchangeAttributeError(Exception): | ||
def __init__(self, attribute_name: str, attribute_value: str) -> None: | ||
self.attribute_name = attribute_name | ||
self.attribute_value = attribute_value | ||
self.message = f"Unknown {attribute_name}: {attribute_value}" | ||
super().__init__(self.message) |
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,16 @@ | ||
import pytest | ||
from exchange.load_exchange_attribute_error import LoadExchangeAttributeError | ||
from exchange.providers import get_provider | ||
|
||
|
||
def test_get_provider_valid(): | ||
provider_name = "openai" | ||
provider = get_provider(provider_name) | ||
assert provider.__name__ == "OpenAiProvider" | ||
|
||
|
||
def test_get_provider_throw_error_for_unknown_provider(): | ||
with pytest.raises(LoadExchangeAttributeError) as error: | ||
get_provider("nonexistent") | ||
assert error.value.attribute_name == "provider" | ||
assert error.value.attribute_value == "nonexistent" |
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,11 @@ | ||
from exchange.load_exchange_attribute_error import LoadExchangeAttributeError | ||
|
||
|
||
def test_load_exchange_attribute_error(): | ||
attribute_name = "provider" | ||
attribute_value = "not_exist" | ||
error = LoadExchangeAttributeError(attribute_name, attribute_value) | ||
|
||
assert error.attribute_name == attribute_name | ||
assert error.attribute_value == attribute_value | ||
assert error.message == "Unknown provider: not_exist" |
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,15 @@ | ||
from exchange.load_exchange_attribute_error import LoadExchangeAttributeError | ||
from exchange.moderators import get_moderator | ||
import pytest | ||
|
||
|
||
def test_get_moderator(): | ||
moderator = get_moderator("truncate") | ||
assert moderator.__name__ == "ContextTruncate" | ||
|
||
|
||
def test_get_moderator_raise_error_for_unknown_moderator(): | ||
with pytest.raises(LoadExchangeAttributeError) as error: | ||
get_moderator("nonexistent") | ||
assert error.value.attribute_name == "moderator" | ||
assert error.value.attribute_value == "nonexistent" |