Skip to content
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

Fix async tests #609

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions test/agentchat/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ async def _test_async_groupchat(credentials: Credentials):


@pytest.mark.parametrize("credentials_from_test_param", credentials_all_llms, indirect=True)
def test_async_groupchat(
@pytest.mark.asyncio
async def test_async_groupchat(
credentials_from_test_param: Credentials,
) -> None:
_test_async_groupchat(credentials_from_test_param)
await _test_async_groupchat(credentials_from_test_param)


async def _test_stream(credentials: Credentials):
Expand Down Expand Up @@ -162,7 +163,8 @@ async def add_data_reply(recipient, messages, sender, config):


@pytest.mark.parametrize("credentials_from_test_param", credentials_all_llms, indirect=True)
def test_stream(
@pytest.mark.asyncio
async def test_stream(
credentials_from_test_param: Credentials,
) -> None:
_test_stream(credentials_from_test_param)
await _test_stream(credentials_from_test_param)
10 changes: 6 additions & 4 deletions test/agentchat/test_async_get_human_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ async def _test_async_get_human_input(credentials: Credentials) -> None:


@pytest.mark.parametrize("credentials_from_test_param", credentials_all_llms, indirect=True)
def test_async_get_human_input(
@pytest.mark.asyncio
async def test_async_get_human_input(
credentials_from_test_param: Credentials,
) -> None:
_test_async_get_human_input(credentials_from_test_param)
await _test_async_get_human_input(credentials_from_test_param)


async def _test_async_max_turn(credentials: Credentials):
Expand Down Expand Up @@ -76,7 +77,8 @@ async def _test_async_max_turn(credentials: Credentials):


@pytest.mark.parametrize("credentials_from_test_param", credentials_all_llms, indirect=True)
def test_async_max_turn(
@pytest.mark.asyncio
async def test_async_max_turn(
credentials_from_test_param: Credentials,
) -> None:
_test_async_max_turn(credentials_from_test_param)
await _test_async_max_turn(credentials_from_test_param)
33 changes: 30 additions & 3 deletions test/agentchat/test_conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import os
import time
import unittest
from typing import Annotated, Any, Callable, Literal
from typing import Annotated, Any, Callable, Literal, Optional
from unittest.mock import MagicMock

import pytest
Expand Down Expand Up @@ -1045,10 +1045,11 @@ def stopwatch(num_seconds: Annotated[str, "Number of seconds in the stopwatch."]


@pytest.mark.parametrize("credentials_from_test_param", credentials_all_llms, indirect=True)
def test_function_registration_e2e_async(
@pytest.mark.asyncio
async def test_function_registration_e2e_async(
credentials_from_test_param: Credentials,
) -> None:
_test_function_registration_e2e_async(credentials_from_test_param)
await _test_function_registration_e2e_async(credentials_from_test_param)


@pytest.mark.openai
Expand Down Expand Up @@ -1542,6 +1543,32 @@ def test_context_variables():
assert agent._context_variables == expected_final_context


@pytest.mark.skip(reason="This test is failing. We need to investigate the issue.")
@pytest.mark.gemini
def test_gemini_with_tools_parameters_set_to_is_annotated_with_none_as_default_value(
credentials_gemini_pro: Credentials,
) -> None:
agent = ConversableAgent(name="agent", llm_config=credentials_gemini_pro.llm_config)

user_proxy = UserProxyAgent(
name="user_proxy_1",
human_input_mode="NEVER",
)

mock = MagicMock()

@user_proxy.register_for_execution()
@agent.register_for_llm(description="Login function")
def login(
additional_notes: Annotated[Optional[str], "Additional notes"] = None,
) -> str:
return "Login successful."

user_proxy.initiate_chat(agent, message="Please login", max_turns=2)

mock.assert_called_once()


if __name__ == "__main__":
# test_trigger()
# test_context()
Expand Down
8 changes: 4 additions & 4 deletions test/agentchat/test_dependancy_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ async def test_register_tools(

assert actual == expected

async def _test_end2end(self, credentials, is_async: bool) -> None:
async def _test_end2end(self, credentials: Credentials, is_async: bool) -> None:
class UserContext(BaseContext, BaseModel):
username: str
password: str
Expand Down Expand Up @@ -243,7 +243,6 @@ async def login(
@agent.register_for_llm(description="Login function")
def login(
user: Annotated[UserContext, Depends(user)],
additional_notes: Annotated[Optional[str], "Additional notes"] = None,
) -> str:
return _login(user)

Expand All @@ -256,9 +255,10 @@ def login(

@pytest.mark.parametrize("credentials_from_test_param", credentials_all_llms, indirect=True)
@pytest.mark.parametrize("is_async", [False, True])
def test_end2end(
@pytest.mark.asyncio
async def test_end2end(
self,
credentials_from_test_param: Credentials,
is_async: bool,
) -> None:
self._test_end2end(credentials_from_test_param, is_async)
await self._test_end2end(credentials_from_test_param, is_async)
Loading