fix role and format ut of serialize_deserialize

This commit is contained in:
better629 2023-11-28 10:47:19 +08:00
parent 9608a20c71
commit c08f6d83d7
9 changed files with 22 additions and 8 deletions

View file

@ -7,12 +7,14 @@ import pytest
from metagpt.actions import Action
from metagpt.llm import LLM
def test_action_serialize():
action = Action()
ser_action_dict = action.dict()
assert "name" in ser_action_dict
assert "llm" in ser_action_dict
@pytest.mark.asyncio
async def test_action_deserialize():
action = Action()

View file

@ -7,6 +7,7 @@ import pytest
from metagpt.roles.architect import Architect
from metagpt.actions.action import Action
def test_architect_serialize():
role = Architect()
ser_role_dict = role.dict(by_alias=True)
@ -14,6 +15,7 @@ def test_architect_serialize():
assert "_states" in ser_role_dict
assert "_actions" in ser_role_dict
@pytest.mark.asyncio
async def test_architect_deserialize():
role = Architect()

View file

@ -8,6 +8,7 @@ from metagpt.roles.product_manager import ProductManager
from metagpt.actions.action import Action
from metagpt.schema import Message
@pytest.mark.asyncio
async def test_product_manager_deserialize():
role = ProductManager()

View file

@ -7,6 +7,7 @@ import pytest
from metagpt.roles.project_manager import ProjectManager
from metagpt.actions.action import Action
def test_project_manager_serialize():
role = ProjectManager()
ser_role_dict = role.dict(by_alias=True)
@ -14,6 +15,7 @@ def test_project_manager_serialize():
assert "_states" in ser_role_dict
assert "_actions" in ser_role_dict
@pytest.mark.asyncio
async def test_project_manager_deserialize():
role = ProjectManager()

View file

@ -34,7 +34,7 @@ async def test_engineer_deserialize():
# also can be deserialized in this way:
new_role = Engineer(**ser_role_dict)
assert new_role.name == "Alex"
assert new_role.use_code_review == True
assert new_role.use_code_review is True
assert len(new_role._actions) == 2
assert isinstance(new_role._actions[0], Action)
assert isinstance(new_role._actions[1], Action)

View file

@ -24,5 +24,5 @@ async def test_action_deserialize():
# new_action = WritePRD().deserialize(serialized_data)
assert new_action.name == ""
assert new_action.llm == LLM()
assert len(await new_action.run([Message(content="write a cli snake game")]))>0
assert len(await new_action.run([Message(content="write a cli snake game")])) > 0

View file

@ -7,18 +7,21 @@ import pytest
from metagpt.actions import WriteCode, WriteCodeReview
from metagpt.llm import LLM
def test_write_design_serialize():
action = WriteCode()
ser_action_dict = action.dict()
assert ser_action_dict["name"] == "WriteCode"
assert "llm" in ser_action_dict
def test_write_task_serialize():
action = WriteCodeReview()
ser_action_dict = action.dict()
assert ser_action_dict["name"] == "WriteCodeReview"
assert "llm" in ser_action_dict
@pytest.mark.asyncio
async def test_write_code_deserialize():
action = WriteCode()
@ -29,6 +32,7 @@ async def test_write_code_deserialize():
assert new_action.llm == LLM()
await new_action.run(context="write a cli snake game", filename="test_code")
@pytest.mark.asyncio
async def test_write_code_review_deserialize():
action = WriteCodeReview()

View file

@ -7,18 +7,21 @@ import pytest
from metagpt.actions import WriteDesign, WriteTasks
from metagpt.llm import LLM
def test_write_design_serialize():
action = WriteDesign()
ser_action_dict = action.dict()
assert "name" in ser_action_dict
assert "llm" in ser_action_dict
def test_write_task_serialize():
action = WriteTasks()
ser_action_dict = action.dict()
assert "name" in ser_action_dict
assert "llm" in ser_action_dict
@pytest.mark.asyncio
async def test_write_design_deserialize():
action = WriteDesign()
@ -28,6 +31,7 @@ async def test_write_design_deserialize():
assert new_action.llm == LLM()
await new_action.run(context="write a cli snake game")
@pytest.mark.asyncio
async def test_write_task_deserialize():
action = WriteTasks()
@ -36,4 +40,4 @@ async def test_write_task_deserialize():
# new_action = WriteTasks().deserialize(serialized_data)
assert new_action.name == "CreateTasks"
assert new_action.llm == LLM()
await new_action.run(context="write a cli snake game")
await new_action.run(context="write a cli snake game")