From 39c00848b9acb58eec0f740a45e99cc0cdbb50ff Mon Sep 17 00:00:00 2001 From: mannaandpoem <1580466765@qq.com> Date: Fri, 19 Jan 2024 19:39:59 +0800 Subject: [PATCH] update test case of ActionNode --- metagpt/roles/engineer.py | 4 +-- tests/metagpt/actions/test_design_api_an.py | 2 +- .../actions/test_project_management_an.py | 2 +- ... => test_write_code_plan_and_change_an.py} | 30 +++++++++---------- tests/metagpt/actions/test_write_prd_an.py | 4 +-- 5 files changed, 20 insertions(+), 22 deletions(-) rename tests/metagpt/actions/{test_write_code_plan_an.py => test_write_code_plan_and_change_an.py} (70%) diff --git a/metagpt/roles/engineer.py b/metagpt/roles/engineer.py index 9bbd32649..75393bc2b 100644 --- a/metagpt/roles/engineer.py +++ b/metagpt/roles/engineer.py @@ -379,8 +379,8 @@ class Engineer(Role): requirement_doc = await FileRepository.get_file(filename=REQUIREMENT_FILENAME, relative_path=DOCS_FILE_REPO) prd_docs = await FileRepository.get_all_files(relative_path=PRDS_FILE_REPO) design_docs = await FileRepository.get_all_files(relative_path=SYSTEM_DESIGN_FILE_REPO) - tasks_file_repo = CONFIG.git_repo.new_file_repository(TASK_FILE_REPO) - tasks_docs = await tasks_file_repo.get_all() + tasks_docs = await FileRepository.get_all_files(relative_path=TASK_FILE_REPO) + code_plan_and_change_context = CodePlanAndChangeContext( requirement_doc=requirement_doc, prd_docs=prd_docs, diff --git a/tests/metagpt/actions/test_design_api_an.py b/tests/metagpt/actions/test_design_api_an.py index fcd2ef666..3d11f200d 100644 --- a/tests/metagpt/actions/test_design_api_an.py +++ b/tests/metagpt/actions/test_design_api_an.py @@ -35,7 +35,7 @@ async def test_write_design_an(mocker): ) 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) + mocker.patch("metagpt.actions.design_api_an.REFINED_DESIGN_NODE.fill", return_value=root) prompt = NEW_REQ_TEMPLATE.format(old_design=DESIGN_SAMPLE, context=dict_to_markdown(REFINED_PRD_JSON)) node = await REFINED_DESIGN_NODE.fill(prompt, llm) diff --git a/tests/metagpt/actions/test_project_management_an.py b/tests/metagpt/actions/test_project_management_an.py index e230151da..aa759aec8 100644 --- a/tests/metagpt/actions/test_project_management_an.py +++ b/tests/metagpt/actions/test_project_management_an.py @@ -35,7 +35,7 @@ async def test_project_management_an(mocker): ) 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) + mocker.patch("metagpt.actions.project_management_an.REFINED_PM_NODE.fill", return_value=root) prompt = NEW_REQ_TEMPLATE.format(old_tasks=TASKS_SAMPLE, context=dict_to_markdown(REFINED_DESIGN_JSON)) node = await REFINED_PM_NODE.fill(prompt, llm) diff --git a/tests/metagpt/actions/test_write_code_plan_an.py b/tests/metagpt/actions/test_write_code_plan_and_change_an.py similarity index 70% rename from tests/metagpt/actions/test_write_code_plan_an.py rename to tests/metagpt/actions/test_write_code_plan_and_change_an.py index 44679e561..33114dfcf 100644 --- a/tests/metagpt/actions/test_write_code_plan_an.py +++ b/tests/metagpt/actions/test_write_code_plan_and_change_an.py @@ -3,7 +3,7 @@ """ @Time : 2024/01/03 @Author : mannaandpoem -@File : test_write_code_plan_an.py +@File : test_write_code_plan_and_change_an.py """ import pytest from openai._models import BaseModel @@ -11,20 +11,16 @@ from openai._models import BaseModel from metagpt.actions.action_node import ActionNode from metagpt.actions.write_code import WriteCode from metagpt.actions.write_code_plan_and_change_an import ( - CODE_PLAN_AND_CHANGE_CONTEXT, REFINED_TEMPLATE, WriteCodePlanAndChange, ) +from metagpt.schema import CodePlanAndChangeContext, Document from tests.data.incremental_dev_project.mock import ( CODE_PLAN_AND_CHANGE_SAMPLE, DESIGN_SAMPLE, NEW_REQUIREMENT_SAMPLE, - OLD_CODE_SAMPLE, REFINED_CODE_INPUT_SAMPLE, REFINED_CODE_SAMPLE, - REFINED_DESIGN_JSON, - REFINED_PRD_JSON, - REFINED_TASKS_JSON, TASKS_SAMPLE, ) @@ -34,23 +30,25 @@ def mock_code_plan_and_change(): @pytest.mark.asyncio -async def test_write_code_plan_an(mocker): +async def test_write_code_plan_and_change_an(mocker): root = ActionNode.from_children( "WriteCodePlanAndChange", [ActionNode(key="", expected_type=str, instruction="", example="")] ) root.instruct_content = BaseModel() root.instruct_content.model_dump = mock_code_plan_and_change - mocker.patch("metagpt.actions.write_code_plan_an.WriteCodePlanAndChange.run", return_value=root) + mocker.patch("metagpt.actions.write_code_plan_and_change_an.WriteCodePlanAndChange.run", return_value=root) - write_code_plan = WriteCodePlanAndChange() - context = CODE_PLAN_AND_CHANGE_CONTEXT.format( - requirement=NEW_REQUIREMENT_SAMPLE, - PRD=REFINED_PRD_JSON, - design=REFINED_DESIGN_JSON, - tasks=REFINED_TASKS_JSON, - code=OLD_CODE_SAMPLE, + requirement_doc = Document() + prd_docs = [Document()] + design_docs = [Document()] + tasks_docs = [Document()] + code_plan_and_change_context = CodePlanAndChangeContext( + requirement_doc=requirement_doc, + prd_docs=prd_docs, + design_docs=design_docs, + tasks_docs=tasks_docs, ) - node = await write_code_plan.run(context=context) + node = await WriteCodePlanAndChange(context=code_plan_and_change_context).run() assert "Plan" in node.instruct_content.model_dump() diff --git a/tests/metagpt/actions/test_write_prd_an.py b/tests/metagpt/actions/test_write_prd_an.py index 806f88d36..3bfb4d3be 100644 --- a/tests/metagpt/actions/test_write_prd_an.py +++ b/tests/metagpt/actions/test_write_prd_an.py @@ -29,10 +29,10 @@ def mock_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 = ActionNode.from_children("RefinedPRD", [ActionNode(key="", expected_type=str, instruction="", example="")]) 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) + mocker.patch("metagpt.actions.write_prd_an.REFINED_PRD_NODE.fill", return_value=root) prompt = REFINED_TEMPLATE.format( requirements=NEW_REQUIREMENT_SAMPLE,