refactor: update component test method and Agent component test for be asynchronous (#5841)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2025-01-21 12:56:06 -03:00 • committed by GitHub
commit a23be65138
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 10 deletions

View file

@ -1,3 +1,4 @@
import asyncio
import inspect
from typing import Any
from unittest.mock import Mock
@ -51,19 +52,19 @@ class ComponentTestBase:
msg = f"{self.__class__.__name__} must implement the file_names_mapping fixture"
raise NotImplementedError(msg)
def component_setup(self, component_class: type[Any], default_kwargs: dict[str, Any]) -> Component:
async def component_setup(self, component_class: type[Any], default_kwargs: dict[str, Any]) -> Component:
mock_vertex = Mock(spec=Vertex)
mock_vertex.graph = Mock(spec=Graph)
mock_vertex.graph.session_id = str(uuid4())
mock_vertex.graph.flow_id = str(uuid4())
source_code = 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._vertex = mock_vertex
return component_instance
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."""
component_instance = self.component_setup(component_class, default_kwargs)
component_instance = await self.component_setup(component_class, default_kwargs)
result = component_instance()
assert result is not None, "Component returned None for the latest version."