mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-26 01:06:27 +02:00
refine utils code
This commit is contained in:
parent
6f166603c4
commit
d3c135edff
3 changed files with 42 additions and 25 deletions
|
|
@ -18,7 +18,7 @@ from metagpt.actions import Action, ActionOutput
|
|||
from metagpt.environment import Environment
|
||||
from metagpt.roles import Role
|
||||
from metagpt.schema import Message
|
||||
from metagpt.utils.common import get_class_name
|
||||
from metagpt.utils.common import any_to_str
|
||||
|
||||
|
||||
class MockAction(Action):
|
||||
|
|
@ -88,13 +88,13 @@ async def test_react():
|
|||
@pytest.mark.asyncio
|
||||
async def test_msg_to():
|
||||
m = Message(content="a", send_to=["a", MockRole, Message])
|
||||
assert m.send_to == set({"a", get_class_name(MockRole), get_class_name(Message)})
|
||||
assert m.send_to == {"a", any_to_str(MockRole), any_to_str(Message)}
|
||||
|
||||
m = Message(content="a", cause_by=MockAction, send_to={"a", MockRole, Message})
|
||||
assert m.send_to == set({"a", get_class_name(MockRole), get_class_name(Message)})
|
||||
assert m.send_to == {"a", any_to_str(MockRole), any_to_str(Message)}
|
||||
|
||||
m = Message(content="a", send_to=("a", MockRole, Message))
|
||||
assert m.send_to == set({"a", get_class_name(MockRole), get_class_name(Message)})
|
||||
assert m.send_to == {"a", any_to_str(MockRole), any_to_str(Message)}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import pytest
|
|||
|
||||
from metagpt.actions import Action
|
||||
from metagpt.schema import AIMessage, Message, SystemMessage, UserMessage
|
||||
from metagpt.utils.common import get_class_name
|
||||
from metagpt.utils.common import any_to_str
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -54,9 +54,9 @@ def test_message():
|
|||
m.cause_by = "Message"
|
||||
assert m.cause_by == "Message"
|
||||
m.cause_by = Action
|
||||
assert m.cause_by == get_class_name(Action)
|
||||
assert m.cause_by == any_to_str(Action)
|
||||
m.cause_by = Action()
|
||||
assert m.cause_by == get_class_name(Action)
|
||||
assert m.cause_by == any_to_str(Action)
|
||||
m.content = "b"
|
||||
assert m.content == "b"
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ def test_routes():
|
|||
m.send_to = "b"
|
||||
assert m.send_to == {"b"}
|
||||
m.send_to = {"e", Action}
|
||||
assert m.send_to == {"e", get_class_name(Action)}
|
||||
assert m.send_to == {"e", any_to_str(Action)}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue