2024-08-28 12:47:04 -04:00
|
|
|
from autogen_core.components import TypeSubscription
|
|
|
|
from autogen_core.base import TopicId, AgentId
|
2024-07-26 14:38:08 -04:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2024-08-28 12:47:04 -04:00
|
|
|
from autogen_core.base.exceptions import CantHandleException
|
2024-07-26 14:38:08 -04:00
|
|
|
|
|
|
|
def test_type_subscription_match() -> None:
|
|
|
|
sub = TypeSubscription(topic_type="t1", agent_type="a1")
|
|
|
|
|
|
|
|
assert sub.is_match(TopicId(type="t0", source="s1")) == False
|
|
|
|
assert sub.is_match(TopicId(type="t1", source="s1")) == True
|
|
|
|
assert sub.is_match(TopicId(type="t1", source="s2")) == True
|
|
|
|
|
|
|
|
|
|
|
|
def test_type_subscription_map() -> None:
|
|
|
|
sub = TypeSubscription(topic_type="t1", agent_type="a1")
|
|
|
|
|
2024-08-07 13:25:44 -04:00
|
|
|
assert sub.map_to_agent(TopicId(type="t1", source="s1")) == AgentId(type="a1", key="s1")
|
2024-07-26 14:38:08 -04:00
|
|
|
|
|
|
|
with pytest.raises(CantHandleException):
|
|
|
|
_agent_id = sub.map_to_agent(TopicId(type="t0", source="s1"))
|