-
Notifications
You must be signed in to change notification settings - Fork 109
feat: add evaluations client passthrough and tests #430
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
Open
nborges-aws
wants to merge
2
commits into
main
Choose a base branch
from
feat/evaluationsClient
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+559
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
155 changes: 155 additions & 0 deletions
155
tests/bedrock_agentcore/evaluation/test_client_passthrough.py
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,155 @@ | ||
| """Tests for EvaluationClient passthrough and *_and_wait methods.""" | ||
|
|
||
| from unittest.mock import Mock, patch | ||
|
|
||
| import pytest | ||
| from botocore.exceptions import ClientError | ||
|
|
||
| from bedrock_agentcore.evaluation.client import EvaluationClient | ||
|
|
||
|
|
||
| class TestEvaluationClientPassthrough: | ||
| """Tests for __getattr__ passthrough.""" | ||
|
|
||
| def _make_client(self): | ||
| with patch("boto3.client"): | ||
| client = EvaluationClient(region_name="us-west-2") | ||
| client._cp_client = Mock() | ||
| client._dp_client = Mock() | ||
| return client | ||
|
|
||
| def test_cp_method_forwarded(self): | ||
| client = self._make_client() | ||
| client._cp_client.get_evaluator.return_value = {"evaluatorId": "e-123"} | ||
| result = client.get_evaluator(evaluatorId="e-123") | ||
| client._cp_client.get_evaluator.assert_called_once_with(evaluatorId="e-123") | ||
| assert result["evaluatorId"] == "e-123" | ||
|
|
||
| def test_dp_method_forwarded(self): | ||
| client = self._make_client() | ||
| client._dp_client.evaluate.return_value = {"evaluationResults": []} | ||
| result = client.evaluate(evaluatorId="e-123") | ||
| client._dp_client.evaluate.assert_called_once_with(evaluatorId="e-123") | ||
| assert result["evaluationResults"] == [] | ||
|
|
||
| def test_snake_case_kwargs_converted(self): | ||
| client = self._make_client() | ||
| client._cp_client.get_evaluator.return_value = {"evaluatorId": "e-123"} | ||
| client.get_evaluator(evaluator_id="e-123") | ||
| client._cp_client.get_evaluator.assert_called_once_with(evaluatorId="e-123") | ||
|
|
||
| def test_non_allowlisted_method_raises(self): | ||
| client = self._make_client() | ||
| with pytest.raises(AttributeError, match="has no attribute"): | ||
| client.not_a_real_method() | ||
|
|
||
| def test_all_cp_methods_in_allowlist(self): | ||
| expected = { | ||
| "create_evaluator", | ||
| "get_evaluator", | ||
| "list_evaluators", | ||
| "update_evaluator", | ||
| "delete_evaluator", | ||
| "create_online_evaluation_config", | ||
| "get_online_evaluation_config", | ||
| "list_online_evaluation_configs", | ||
| "update_online_evaluation_config", | ||
| "delete_online_evaluation_config", | ||
| } | ||
| assert expected == EvaluationClient._ALLOWED_CP_METHODS | ||
|
|
||
| def test_all_dp_methods_in_allowlist(self): | ||
| expected = {"evaluate"} | ||
| assert expected == EvaluationClient._ALLOWED_DP_METHODS | ||
|
|
||
|
|
||
| class TestEvaluationAndWait: | ||
| """Tests for *_and_wait methods.""" | ||
|
|
||
| def _make_client(self): | ||
| with patch("boto3.client"): | ||
| client = EvaluationClient(region_name="us-west-2") | ||
| client._cp_client = Mock() | ||
| client._dp_client = Mock() | ||
| return client | ||
|
|
||
| def test_create_evaluator_and_wait(self): | ||
| client = self._make_client() | ||
| client._cp_client.create_evaluator.return_value = {"evaluatorId": "e-123"} | ||
| client._cp_client.get_evaluator.return_value = { | ||
| "status": "ACTIVE", | ||
| "evaluatorId": "e-123", | ||
| } | ||
| result = client.create_evaluator_and_wait(evaluatorName="test") | ||
| assert result["status"] == "ACTIVE" | ||
|
|
||
| def test_create_evaluator_and_wait_failed(self): | ||
| client = self._make_client() | ||
| client._cp_client.create_evaluator.return_value = {"evaluatorId": "e-123"} | ||
| client._cp_client.get_evaluator.return_value = {"status": "CREATE_FAILED"} | ||
| with pytest.raises(RuntimeError, match="CREATE_FAILED"): | ||
| client.create_evaluator_and_wait(evaluatorName="test") | ||
|
|
||
| def test_update_evaluator_and_wait(self): | ||
| client = self._make_client() | ||
| client._cp_client.update_evaluator.return_value = {"evaluatorId": "e-123"} | ||
| client._cp_client.get_evaluator.return_value = { | ||
| "status": "ACTIVE", | ||
| "evaluatorId": "e-123", | ||
| } | ||
| result = client.update_evaluator_and_wait(evaluatorId="e-123") | ||
| assert result["status"] == "ACTIVE" | ||
|
|
||
| def test_create_online_eval_config_and_wait(self): | ||
| client = self._make_client() | ||
| client._cp_client.create_online_evaluation_config.return_value = { | ||
| "onlineEvaluationConfigId": "c-123", | ||
| } | ||
| client._cp_client.get_online_evaluation_config.return_value = { | ||
| "status": "ACTIVE", | ||
| "onlineEvaluationConfigId": "c-123", | ||
| } | ||
| result = client.create_online_evaluation_config_and_wait( | ||
| onlineEvaluationConfigName="test", | ||
| ) | ||
| assert result["status"] == "ACTIVE" | ||
|
|
||
| def test_update_online_eval_config_and_wait(self): | ||
| client = self._make_client() | ||
| client._cp_client.update_online_evaluation_config.return_value = { | ||
| "onlineEvaluationConfigId": "c-123", | ||
| } | ||
| client._cp_client.get_online_evaluation_config.return_value = { | ||
| "status": "ACTIVE", | ||
| "onlineEvaluationConfigId": "c-123", | ||
| } | ||
| result = client.update_online_evaluation_config_and_wait( | ||
| onlineEvaluationConfigId="c-123", | ||
| ) | ||
| assert result["status"] == "ACTIVE" | ||
|
|
||
| @patch("bedrock_agentcore._utils.polling.time.sleep") | ||
| def test_delete_evaluator_and_wait(self, _mock_sleep): | ||
| client = self._make_client() | ||
| client._cp_client.delete_evaluator.return_value = {"evaluatorId": "e-123"} | ||
| client._cp_client.get_evaluator.side_effect = ClientError( | ||
| {"Error": {"Code": "ResourceNotFoundException", "Message": "gone"}}, | ||
| "GetEvaluator", | ||
| ) | ||
| client.delete_evaluator_and_wait(evaluatorId="e-123") | ||
| client._cp_client.delete_evaluator.assert_called_once() | ||
|
|
||
| @patch("bedrock_agentcore._utils.polling.time.sleep") | ||
| def test_delete_online_eval_config_and_wait(self, _mock_sleep): | ||
| client = self._make_client() | ||
| client._cp_client.delete_online_evaluation_config.return_value = { | ||
| "onlineEvaluationConfigId": "c-123", | ||
| } | ||
| client._cp_client.get_online_evaluation_config.side_effect = ClientError( | ||
| {"Error": {"Code": "ResourceNotFoundException", "Message": "gone"}}, | ||
| "GetOnlineEvaluationConfig", | ||
| ) | ||
| client.delete_online_evaluation_config_and_wait( | ||
| onlineEvaluationConfigId="c-123", | ||
| ) | ||
| client._cp_client.delete_online_evaluation_config.assert_called_once() |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we consolidate these two? Also, is there a DELETE_FAILED? I know there are for other primitives but not confident on evaluators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep will consolidate. I checked the service models, evaluators has DELETING, but no DELETE_FAILED