mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-15 11:02:36 +02:00
feat: +unit test
This commit is contained in:
parent
2ed47e3eb2
commit
6379a091ce
1 changed files with 44 additions and 41 deletions
|
|
@ -21,6 +21,7 @@ from metagpt.roles import (
|
|||
ProductManager,
|
||||
ProjectManager,
|
||||
QaEngineer,
|
||||
Role,
|
||||
)
|
||||
from metagpt.schema import Message, UserMessage
|
||||
from metagpt.utils.common import any_to_str, is_send_to
|
||||
|
|
@ -28,47 +29,6 @@ from metagpt.utils.common import any_to_str, is_send_to
|
|||
serdeser_path = Path(__file__).absolute().parent.joinpath("../data/serdeser_storage")
|
||||
|
||||
|
||||
# @pytest.fixture
|
||||
# def env():
|
||||
# return Environment()
|
||||
#
|
||||
#
|
||||
# def test_add_role(env: Environment):
|
||||
# role = ProductManager(
|
||||
# name="Alice", profile="product manager", goal="create a new product", constraints="limited resources"
|
||||
# )
|
||||
# env.add_role(role)
|
||||
# assert env.get_role(role.profile) == role
|
||||
#
|
||||
#
|
||||
# def test_get_roles(env: Environment):
|
||||
# role1 = Role(name="Alice", profile="product manager", goal="create a new product", constraints="limited resources")
|
||||
# role2 = Role(name="Bob", profile="engineer", goal="develop the new product", constraints="short deadline")
|
||||
# env.add_role(role1)
|
||||
# env.add_role(role2)
|
||||
# roles = env.get_roles()
|
||||
# assert roles == {role1.profile: role1, role2.profile: role2}
|
||||
#
|
||||
#
|
||||
# @pytest.mark.asyncio
|
||||
# async def test_publish_and_process_message(env: Environment):
|
||||
# if env.context.git_repo:
|
||||
# env.context.git_repo.delete_repository()
|
||||
# env.context.git_repo = None
|
||||
#
|
||||
# product_manager = ProductManager(name="Alice", profile="Product Manager", goal="做AI Native产品", constraints="资源有限")
|
||||
# architect = Architect(
|
||||
# name="Bob", profile="Architect", goal="设计一个可用、高效、较低成本的系统,包括数据结构与接口", constraints="资源有限,需要节省成本"
|
||||
# )
|
||||
#
|
||||
# env.add_roles([product_manager, architect])
|
||||
#
|
||||
# env.publish_message(Message(role="User", content="需要一个基于LLM做总结的搜索引擎", cause_by=UserRequirement))
|
||||
# await env.run(k=2)
|
||||
# logger.info(f"{env.history}")
|
||||
# assert len(env.history.storage) > 10
|
||||
|
||||
|
||||
class MockEnv(Environment):
|
||||
def publish_message(self, message: Message, peekable: bool = True) -> bool:
|
||||
consumers = []
|
||||
|
|
@ -84,6 +44,49 @@ class MockEnv(Environment):
|
|||
return True
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def env():
|
||||
context = Context()
|
||||
context.kwargs.tag = __file__
|
||||
return MockEnv(context=context)
|
||||
|
||||
|
||||
def test_add_role(env: Environment):
|
||||
role = ProductManager(
|
||||
name="Alice", profile="product manager", goal="create a new product", constraints="limited resources"
|
||||
)
|
||||
env.add_role(role)
|
||||
assert env.get_role(role.profile) == role
|
||||
|
||||
|
||||
def test_get_roles(env: Environment):
|
||||
role1 = Role(name="Alice", profile="product manager", goal="create a new product", constraints="limited resources")
|
||||
role2 = Role(name="Bob", profile="engineer", goal="develop the new product", constraints="short deadline")
|
||||
env.add_role(role1)
|
||||
env.add_role(role2)
|
||||
roles = env.get_roles()
|
||||
assert roles == {role1.profile: role1, role2.profile: role2}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_publish_and_process_message(env: Environment):
|
||||
if env.context.git_repo:
|
||||
env.context.git_repo.delete_repository()
|
||||
env.context.git_repo = None
|
||||
|
||||
product_manager = ProductManager(name="Alice", profile="Product Manager", goal="做AI Native产品", constraints="资源有限")
|
||||
architect = Architect(
|
||||
name="Bob", profile="Architect", goal="设计一个可用、高效、较低成本的系统,包括数据结构与接口", constraints="资源有限,需要节省成本"
|
||||
)
|
||||
|
||||
env.add_roles([product_manager, architect])
|
||||
|
||||
env.publish_message(UserMessage(content="需要一个基于LLM做总结的搜索引擎", cause_by=UserRequirement, send_to=product_manager))
|
||||
await env.run(k=2)
|
||||
logger.info(f"{env.history}")
|
||||
assert len(env.history.storage) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
("content", "send_to"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue