You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_subscription.py 777 B

12345678910111213141516171819202122
  1. from agnext.components import TypeSubscription
  2. from agnext.core import TopicId, AgentId
  3. import pytest
  4. from agnext.core.exceptions import CantHandleException
  5. def test_type_subscription_match() -> None:
  6. sub = TypeSubscription(topic_type="t1", agent_type="a1")
  7. assert sub.is_match(TopicId(type="t0", source="s1")) == False
  8. assert sub.is_match(TopicId(type="t1", source="s1")) == True
  9. assert sub.is_match(TopicId(type="t1", source="s2")) == True
  10. def test_type_subscription_map() -> None:
  11. sub = TypeSubscription(topic_type="t1", agent_type="a1")
  12. assert sub.map_to_agent(TopicId(type="t1", source="s1")) == AgentId(type="a1", key="s1")
  13. with pytest.raises(CantHandleException):
  14. _agent_id = sub.map_to_agent(TopicId(type="t0", source="s1"))