Skip to content

Commit

Permalink
remove not needed test
Browse files Browse the repository at this point in the history
  • Loading branch information
aakrem committed May 21, 2024
1 parent e83e454 commit 2087286
Showing 1 changed file with 24 additions and 40 deletions.
64 changes: 24 additions & 40 deletions agenta-backend/agenta_backend/tests/unit/test_llm_apps_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from unittest.mock import patch, AsyncMock
import asyncio
import aiohttp
import json

from agenta_backend.services.llm_apps_service import (
batch_invoke,
Expand All @@ -14,6 +13,13 @@

@pytest.mark.asyncio
async def test_batch_invoke_success():
"""
Test the successful invocation of batch_invoke function.
This test mocks the get_parameters_from_openapi and invoke_app functions
to simulate successful invocations. It verifies that the batch_invoke
function correctly returns the expected results for the given test data.
"""
with patch(
"agenta_backend.services.llm_apps_service.get_parameters_from_openapi",
new_callable=AsyncMock,
Expand Down Expand Up @@ -61,6 +67,14 @@ def invoke_app_side_effect(uri, datapoint, parameters, openapi_parameters):

@pytest.mark.asyncio
async def test_batch_invoke_retries_and_failure():
"""
Test the batch_invoke function with retries and eventual failure.
This test mocks the get_parameters_from_openapi and invoke_app functions
to simulate failures that trigger retries. It verifies that the batch_invoke
function correctly retries the specified number of times and returns an error
result after reaching the maximum retries.
"""
with patch(
"agenta_backend.services.llm_apps_service.get_parameters_from_openapi",
new_callable=AsyncMock,
Expand Down Expand Up @@ -102,46 +116,16 @@ def invoke_app_side_effect(uri, datapoint, parameters, openapi_parameters):
assert results[1].result.error.message == "Max retries reached"


@pytest.mark.asyncio
async def test_batch_invoke_json_decode_error():
with patch(
"agenta_backend.services.llm_apps_service.get_parameters_from_openapi",
new_callable=AsyncMock,
) as mock_get_parameters_from_openapi, patch(
"agenta_backend.services.llm_apps_service.invoke_app", new_callable=AsyncMock
) as mock_invoke_app, patch(
"asyncio.sleep", new_callable=AsyncMock
) as mock_sleep:
mock_get_parameters_from_openapi.return_value = [
{"name": "param1", "type": "input"},
{"name": "param2", "type": "input"},
]

# Mock the response of invoke_app to raise json.JSONDecodeError
def invoke_app_side_effect(uri, datapoint, parameters, openapi_parameters):
raise json.JSONDecodeError("Expecting value", "", 0)

mock_invoke_app.side_effect = invoke_app_side_effect

uri = "http://example.com"
testset_data = [{"id": 1, "param1": "value1", "param2": "value2"}]
parameters = {}
rate_limit_config = {
"batch_size": 1,
"max_retries": 3,
"retry_delay": 1,
"delay_between_batches": 1,
}

results = await batch_invoke(uri, testset_data, parameters, rate_limit_config)

assert len(results) == 1
assert results[0].result.type == "error"
assert "Failed to decode JSON from response" in results[0].result.error.message


@pytest.mark.asyncio
async def test_batch_invoke_generic_exception():
"""
Test the batch_invoke function with a generic exception.
This test mocks the get_parameters_from_openapi and invoke_app functions
to simulate a generic exception during invocation. It verifies that the
batch_invoke function correctly handles the exception and returns an error
result with the appropriate error message.
"""
with patch(
"agenta_backend.services.llm_apps_service.get_parameters_from_openapi",
new_callable=AsyncMock,
Expand Down Expand Up @@ -175,4 +159,4 @@ def invoke_app_side_effect(uri, datapoint, parameters, openapi_parameters):

assert len(results) == 1
assert results[0].result.type == "error"
assert "Generic Error" in results[0].result.error.message
assert results[0].result.error.message == "Max retries reached"

0 comments on commit 2087286

Please sign in to comment.