Skip to content

Commit

Permalink
Add await to async tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rjambrecic committed Jan 22, 2025
1 parent 1cc16a9 commit ec1eb3e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
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)
5 changes: 3 additions & 2 deletions test/agentchat/test_conversable_agent.py
Original file line number Diff line number Diff line change
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
34 changes: 30 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,36 @@ 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)

@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(
self,
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()

0 comments on commit ec1eb3e

Please sign in to comment.