fix: make sure tests run async (#5842)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2025-01-21 13:16:33 -03:00 • committed by GitHub
commit 86b83b0f64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 12 deletions

View file

@ -59,13 +59,14 @@ class ComponentTestBase:
mock_vertex.graph.flow_id = str(uuid4()) mock_vertex.graph.flow_id = str(uuid4())
source_code = await asyncio.to_thread(inspect.getsource, component_class) source_code = await asyncio.to_thread(inspect.getsource, component_class)
component_instance = component_class(_code=source_code, **default_kwargs) component_instance = component_class(_code=source_code, **default_kwargs)
component_instance._should_process_output = Mock(return_value=False)
component_instance._vertex = mock_vertex component_instance._vertex = mock_vertex
return component_instance return component_instance
async def test_latest_version(self, component_class: type[Any], default_kwargs: dict[str, Any]) -> None: async def test_latest_version(self, component_class: type[Any], default_kwargs: dict[str, Any]) -> None:
"""Test that the component works with the latest version.""" """Test that the component works with the latest version."""
component_instance = await self.component_setup(component_class, default_kwargs) component_instance = await self.component_setup(component_class, default_kwargs)
result = component_instance() result = await component_instance.run()
assert result is not None, "Component returned None for the latest version." assert result is not None, "Component returned None for the latest version."
def test_all_versions_have_a_file_name_defined(self, file_names_mapping: list[VersionComponentMapping]) -> None: def test_all_versions_have_a_file_name_defined(self, file_names_mapping: list[VersionComponentMapping]) -> None:

View file

@ -1,3 +1,4 @@
import asyncio
import inspect import inspect
from typing import Any from typing import Any
@ -65,7 +66,7 @@ async def test_update_component_model_name_options(client: AsyncClient, logged_i
# load the code from the file at langflow.components.agents.agent.py asynchronously # load the code from the file at langflow.components.agents.agent.py asynchronously
# we are at str/backend/tests/unit/api/v1/test_endpoints.py # we are at str/backend/tests/unit/api/v1/test_endpoints.py
# find the file by using the class AgentComponent # find the file by using the class AgentComponent
agent_component_file = inspect.getsourcefile(AgentComponent) agent_component_file = await asyncio.to_thread(inspect.getsourcefile, AgentComponent)
async with async_open(agent_component_file, encoding="utf-8") as f: async with async_open(agent_component_file, encoding="utf-8") as f:
code = await f.read() code = await f.read()
@ -87,12 +88,12 @@ async def test_update_component_model_name_options(client: AsyncClient, logged_i
assert "template" in result assert "template" in result
assert "model_name" in result["template"] assert "model_name" in result["template"]
assert isinstance(result["template"]["model_name"]["options"], list) assert isinstance(result["template"]["model_name"]["options"], list)
assert len(result["template"]["model_name"]["options"]) > 0, ( assert (
f"Model names: {result['template']['model_name']['options']}" len(result["template"]["model_name"]["options"]) > 0
) ), f"Model names: {result['template']['model_name']['options']}"
assert current_model_names != result["template"]["model_name"]["options"], ( assert (
f"Current model names: {current_model_names}, New model names: {result['template']['model_name']['options']}" current_model_names != result["template"]["model_name"]["options"]
) ), f"Current model names: {current_model_names}, New model names: {result['template']['model_name']['options']}"
# Now test with Custom provider # Now test with Custom provider
template["agent_llm"]["value"] = "Custom" template["agent_llm"]["value"] = "Custom"
request.field_value = "Custom" request.field_value = "Custom"

View file

@ -12,7 +12,6 @@ from langflow.memory import (
aupdate_messages, aupdate_messages,
delete_messages, delete_messages,
get_messages, get_messages,
store_message,
) )
from langflow.schema.content_block import ContentBlock from langflow.schema.content_block import ContentBlock
from langflow.schema.content_types import TextContent, ToolContent from langflow.schema.content_types import TextContent, ToolContent
@ -125,11 +124,11 @@ async def test_adelete_messages():
@pytest.mark.usefixtures("client") @pytest.mark.usefixtures("client")
def test_store_message(): async def test_store_message():
session_id = "stored_session_id" session_id = "stored_session_id"
message = Message(text="Stored message", sender="User", sender_name="User", session_id=session_id) message = Message(text="Stored message", sender="User", sender_name="User", session_id=session_id)
store_message(message) await astore_message(message)
stored_messages = get_messages(sender="User", session_id=session_id) stored_messages = await aget_messages(sender="User", session_id=session_id)
assert len(stored_messages) == 1 assert len(stored_messages) == 1
assert stored_messages[0].text == "Stored message" assert stored_messages[0].text == "Stored message"