update test file of ActionNode

This commit is contained in:
mannaandpoem 2024-01-18 10:01:33 +08:00
parent db086e47e7
commit fe64b23a0e
4 changed files with 47 additions and 21 deletions

View file

@ -6,6 +6,7 @@
@File : test_design_api_an.py
"""
import pytest
from openai._models import BaseModel
from metagpt.actions.action_node import ActionNode, dict_to_markdown
from metagpt.actions.design_api import NEW_REQ_TEMPLATE
@ -23,17 +24,23 @@ def llm():
return LLM()
def mock_refined_design_json():
return REFINED_DESIGN_JSON
@pytest.mark.asyncio
async def test_write_design_an(mocker):
root = ActionNode.from_children(
"RefinedDesignAPI", [ActionNode(key="", expected_type=str, instruction="", example="")]
)
root.instruct_content = REFINED_DESIGN_JSON
root.instruct_content = BaseModel()
root.instruct_content.model_dump = mock_refined_design_json
mocker.patch("metagpt.actions.design_api_an.REFINED_DESIGN_NODES.fill", return_value=root)
prompt = NEW_REQ_TEMPLATE.format(old_design=DESIGN_SAMPLE, context=dict_to_markdown(REFINED_PRD_JSON))
node = await REFINED_DESIGN_NODES.fill(prompt, llm)
assert "Refined Implementation Approach" in node.instruct_content
assert "Refined File list" in node.instruct_content
assert "Refined Data structures and interfaces" in node.instruct_content
assert "Refined Program call flow" in node.instruct_content
assert "Refined Implementation Approach" in node.instruct_content.model_dump()
assert "Refined File list" in node.instruct_content.model_dump()
assert "Refined Data structures and interfaces" in node.instruct_content.model_dump()
assert "Refined Program call flow" in node.instruct_content.model_dump()

View file

@ -6,6 +6,7 @@
@File : test_project_management_an.py
"""
import pytest
from openai._models import BaseModel
from metagpt.actions.action_node import ActionNode, dict_to_markdown
from metagpt.actions.project_management import NEW_REQ_TEMPLATE
@ -23,18 +24,22 @@ def llm():
return LLM()
def mock_refined_tasks_json():
return REFINED_TASKS_JSON
@pytest.mark.asyncio
async def test_project_management_an(mocker):
root = ActionNode.from_children(
"RefinedProjectManagement", [ActionNode(key="", expected_type=str, instruction="", example="")]
)
root.instruct_content = REFINED_TASKS_JSON
root.instruct_content = BaseModel()
root.instruct_content.model_dump = mock_refined_tasks_json
mocker.patch("metagpt.actions.project_management_an.REFINED_PM_NODES.fill", return_value=root)
prompt = NEW_REQ_TEMPLATE.format(old_tasks=TASKS_SAMPLE, context=dict_to_markdown(REFINED_DESIGN_JSON))
node = await REFINED_PM_NODES.fill(prompt, llm)
assert node.instruct_content
assert "Refined Logic Analysis" in node.instruct_content
assert "Refined Task list" in node.instruct_content
assert "Refined Shared Knowledge" in node.instruct_content
assert "Refined Logic Analysis" in node.instruct_content.model_dump()
assert "Refined Task list" in node.instruct_content.model_dump()
assert "Refined Shared Knowledge" in node.instruct_content.model_dump()

View file

@ -6,6 +6,7 @@
@File : test_write_code_guideline_an.py
"""
import pytest
from openai._models import BaseModel
from metagpt.actions.action_node import ActionNode
from metagpt.actions.write_code import WriteCode
@ -28,12 +29,17 @@ from tests.data.incremental_dev_project.mock import (
)
def mock_guidelines_and_incremental_change():
return GUIDELINES_AND_INCREMENTAL_CHANGE_SAMPLE
@pytest.mark.asyncio
async def test_write_code_guideline_an(mocker):
root = ActionNode.from_children(
"WriteCodeGuideline", [ActionNode(key="", expected_type=str, instruction="", example="")]
)
root.instruct_content = GUIDELINES_AND_INCREMENTAL_CHANGE_SAMPLE
root.instruct_content = BaseModel()
root.instruct_content.model_dump = mock_guidelines_and_incremental_change
mocker.patch("metagpt.actions.write_code_guideline_an.WriteCodeGuideline.run", return_value=root)
write_code_guideline = WriteCodeGuideline()
@ -45,7 +51,8 @@ async def test_write_code_guideline_an(mocker):
code=OLD_CODE_SAMPLE,
)
node = await write_code_guideline.run(context=context)
assert "Guidelines and Incremental Change" in node.instruct_content
assert "Guidelines and Incremental Change" in node.instruct_content.model_dump()
@pytest.mark.asyncio

View file

@ -6,6 +6,7 @@
@File : test_write_prd_an.py
"""
import pytest
from openai._models import BaseModel
from metagpt.actions.action_node import ActionNode
from metagpt.actions.write_prd_an import REFINE_PRD_NODE, REFINE_PRD_TEMPLATE
@ -22,20 +23,26 @@ def llm():
return LLM()
def mock_refined_prd_json():
return REFINED_PRD_JSON
@pytest.mark.asyncio
async def test_write_prd_an(mocker):
root = ActionNode.from_children("RefinePRD", [ActionNode(key="", expected_type=str, instruction="", example="")])
root.instruct_content = REFINED_PRD_JSON
root.instruct_content = BaseModel()
root.instruct_content.model_dump = mock_refined_prd_json
mocker.patch("metagpt.actions.write_prd_an.REFINE_PRD_NODE.fill", return_value=root)
prompt = REFINE_PRD_TEMPLATE.format(
requirements=NEW_REQUIREMENT_SAMPLE,
old_prd=PRD_SAMPLE,
project_name="",
)
node = await REFINE_PRD_NODE.fill(prompt, llm)
assert "Refined Requirements" in node.instruct_content
assert "Refined Product Goals" in node.instruct_content
assert "Refined User Stories" in node.instruct_content
assert "Refined Requirement Analysis" in node.instruct_content
assert "Refined Requirement Pool" in node.instruct_content
assert "Refined Requirements" in node.instruct_content.model_dump()
assert "Refined Product Goals" in node.instruct_content.model_dump()
assert "Refined User Stories" in node.instruct_content.model_dump()
assert "Refined Requirement Analysis" in node.instruct_content.model_dump()
assert "Refined Requirement Pool" in node.instruct_content.model_dump()