fix env=None when init Team with env=xxx

This commit is contained in:
better629 2023-12-27 16:34:43 +08:00
parent 7d523b3922
commit 2dbaee0ff2
4 changed files with 53 additions and 60 deletions

View file

@ -9,38 +9,40 @@ import pytest
from metagpt.const import SERDESER_PATH
from metagpt.logs import logger
from metagpt.roles import Architect, ProductManager, ProjectManager
from metagpt.team import Team
from tests.metagpt.serialize_deserialize.test_serdeser_base import (
ActionOK,
RoleA,
RoleB,
RoleC,
serdeser_path,
)
# def test_team_deserialize():
# company = Team()
#
# pm = ProductManager()
# arch = Architect()
# company.hire(
# [
# pm,
# arch,
# ProjectManager(),
# ]
# )
# assert len(company.env.get_roles()) == 3
# ser_company = company.model_dump()
# print("ser_company ", ser_company)
# new_company = Team.model_validate(ser_company)
#
# assert len(new_company.env.get_roles()) == 3
# assert new_company.env.get_role(pm.profile) is not None
#
# new_pm = new_company.env.get_role(pm.profile)
# assert type(new_pm) == ProductManager
# assert new_company.env.get_role(pm.profile) is not None
# assert new_company.env.get_role(arch.profile) is not None
def test_team_deserialize():
company = Team()
pm = ProductManager()
arch = Architect()
company.hire(
[
pm,
arch,
ProjectManager(),
]
)
assert len(company.env.get_roles()) == 3
ser_company = company.model_dump()
new_company = Team.model_validate(ser_company)
assert len(new_company.env.get_roles()) == 3
assert new_company.env.get_role(pm.profile) is not None
new_pm = new_company.env.get_role(pm.profile)
assert type(new_pm) == ProductManager
assert new_company.env.get_role(pm.profile) is not None
assert new_company.env.get_role(arch.profile) is not None
def test_team_serdeser_save():
@ -58,30 +60,30 @@ def test_team_serdeser_save():
assert len(new_company.env.roles) == 1
# @pytest.mark.asyncio
# async def test_team_recover():
# idea = "write a snake game"
# stg_path = SERDESER_PATH.joinpath("team")
# shutil.rmtree(stg_path, ignore_errors=True)
#
# company = Team()
# role_c = RoleC()
# company.hire([role_c])
# company.run_project(idea)
# await company.run(n_round=4)
#
# ser_data = company.model_dump()
# new_company = Team(**ser_data)
#
# new_role_c = new_company.env.get_role(role_c.profile)
# # assert new_role_c.rc.memory == role_c.rc.memory # TODO
# assert new_role_c.rc.env != role_c.rc.env # TODO
# assert type(list(new_company.env.roles.values())[0].actions[0]) == ActionOK
#
# new_company.run_project(idea)
# await new_company.run(n_round=4)
#
#
@pytest.mark.asyncio
async def test_team_recover():
idea = "write a snake game"
stg_path = SERDESER_PATH.joinpath("team")
shutil.rmtree(stg_path, ignore_errors=True)
company = Team()
role_c = RoleC()
company.hire([role_c])
company.run_project(idea)
await company.run(n_round=4)
ser_data = company.model_dump()
new_company = Team(**ser_data)
new_company.env.get_role(role_c.profile)
# assert new_role_c.rc.memory == role_c.rc.memory # TODO
# assert new_role_c.rc.env != role_c.rc.env # TODO
assert type(list(new_company.env.roles.values())[0].actions[0]) == ActionOK
new_company.run_project(idea)
await new_company.run(n_round=4)
@pytest.mark.asyncio
async def test_team_recover_save():
idea = "write a 2048 web game"