mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-30 14:35:17 +02:00
refactor learn and roles, add mock config
This commit is contained in:
parent
4e9a794629
commit
2bcce1d593
5 changed files with 73 additions and 26 deletions
|
|
@ -24,7 +24,7 @@ async def test_text_to_image(mocker):
|
|||
mocker.patch.object(OpenAIText2Image, "text_2_image", return_value=b"mock OpenAIText2Image")
|
||||
mocker.patch.object(S3, "cache", return_value="http://mock/s3")
|
||||
|
||||
config = Config()
|
||||
config = Config.default()
|
||||
assert config.METAGPT_TEXT_TO_IMAGE_MODEL_URL
|
||||
|
||||
data = await text_to_image("Panda emoji", size_type="512x512", model_url=config.METAGPT_TEXT_TO_IMAGE_MODEL_URL)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ from pathlib import Path
|
|||
import pytest
|
||||
|
||||
from metagpt.actions import WriteCode, WriteTasks
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.const import (
|
||||
PRDS_FILE_REPO,
|
||||
REQUIREMENT_FILENAME,
|
||||
|
|
@ -45,7 +44,7 @@ async def test_engineer():
|
|||
|
||||
logger.info(rsp)
|
||||
assert rsp.cause_by == any_to_str(WriteCode)
|
||||
src_file_repo = CONFIG.git_repo.new_file_repository(CONFIG.src_workspace)
|
||||
src_file_repo = context.git_repo.new_file_repository(context.src_workspace)
|
||||
assert src_file_repo.changed_files
|
||||
|
||||
|
||||
|
|
@ -117,19 +116,19 @@ async def test_new_coding_context():
|
|||
# Prerequisites
|
||||
demo_path = Path(__file__).parent / "../../data/demo_project"
|
||||
deps = json.loads(await aread(demo_path / "dependencies.json"))
|
||||
dependency = await CONFIG.git_repo.get_dependency()
|
||||
dependency = await context.git_repo.get_dependency()
|
||||
for k, v in deps.items():
|
||||
await dependency.update(k, set(v))
|
||||
data = await aread(demo_path / "system_design.json")
|
||||
rqno = "20231221155954.json"
|
||||
await awrite(CONFIG.git_repo.workdir / SYSTEM_DESIGN_FILE_REPO / rqno, data)
|
||||
await awrite(context.git_repo.workdir / SYSTEM_DESIGN_FILE_REPO / rqno, data)
|
||||
data = await aread(demo_path / "tasks.json")
|
||||
await awrite(CONFIG.git_repo.workdir / TASK_FILE_REPO / rqno, data)
|
||||
await awrite(context.git_repo.workdir / TASK_FILE_REPO / rqno, data)
|
||||
|
||||
CONFIG.src_workspace = Path(CONFIG.git_repo.workdir) / "game_2048"
|
||||
src_file_repo = CONFIG.git_repo.new_file_repository(relative_path=CONFIG.src_workspace)
|
||||
task_file_repo = CONFIG.git_repo.new_file_repository(relative_path=TASK_FILE_REPO)
|
||||
design_file_repo = CONFIG.git_repo.new_file_repository(relative_path=SYSTEM_DESIGN_FILE_REPO)
|
||||
context.src_workspace = Path(context.git_repo.workdir) / "game_2048"
|
||||
src_file_repo = context.git_repo.new_file_repository(relative_path=context.src_workspace)
|
||||
task_file_repo = context.git_repo.new_file_repository(relative_path=TASK_FILE_REPO)
|
||||
design_file_repo = context.git_repo.new_file_repository(relative_path=SYSTEM_DESIGN_FILE_REPO)
|
||||
|
||||
filename = "game.py"
|
||||
ctx_doc = await Engineer._new_coding_doc(
|
||||
|
|
@ -150,8 +149,8 @@ async def test_new_coding_context():
|
|||
assert ctx.task_doc.content
|
||||
assert ctx.code_doc
|
||||
|
||||
CONFIG.git_repo.add_change({f"{TASK_FILE_REPO}/{rqno}": ChangeType.UNTRACTED})
|
||||
CONFIG.git_repo.commit("mock env")
|
||||
context.git_repo.add_change({f"{TASK_FILE_REPO}/{rqno}": ChangeType.UNTRACTED})
|
||||
context.git_repo.commit("mock env")
|
||||
await src_file_repo.save(filename=filename, content="content")
|
||||
role = Engineer()
|
||||
assert not role.code_todos
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from pydantic import Field
|
|||
|
||||
from metagpt.actions import DebugError, RunCode, WriteTest
|
||||
from metagpt.actions.summarize_code import SummarizeCode
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.context import context
|
||||
from metagpt.environment import Environment
|
||||
from metagpt.roles import QaEngineer
|
||||
from metagpt.schema import Message
|
||||
|
|
@ -23,10 +23,10 @@ from metagpt.utils.common import any_to_str, aread, awrite
|
|||
async def test_qa():
|
||||
# Prerequisites
|
||||
demo_path = Path(__file__).parent / "../../data/demo_project"
|
||||
CONFIG.src_workspace = Path(CONFIG.git_repo.workdir) / "qa/game_2048"
|
||||
context.src_workspace = Path(context.git_repo.workdir) / "qa/game_2048"
|
||||
data = await aread(filename=demo_path / "game.py", encoding="utf-8")
|
||||
await awrite(filename=CONFIG.src_workspace / "game.py", data=data, encoding="utf-8")
|
||||
await awrite(filename=Path(CONFIG.git_repo.workdir) / "requirements.txt", data="")
|
||||
await awrite(filename=context.src_workspace / "game.py", data=data, encoding="utf-8")
|
||||
await awrite(filename=Path(context.git_repo.workdir) / "requirements.txt", data="")
|
||||
|
||||
class MockEnv(Environment):
|
||||
msgs: List[Message] = Field(default_factory=list)
|
||||
|
|
|
|||
|
|
@ -5,13 +5,12 @@
|
|||
@Author : mashenquan
|
||||
@File : test_teacher.py
|
||||
"""
|
||||
import os
|
||||
from typing import Dict, Optional
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel
|
||||
|
||||
from metagpt.config import CONFIG, Config
|
||||
from metagpt.context import context
|
||||
from metagpt.roles.teacher import Teacher
|
||||
from metagpt.schema import Message
|
||||
|
||||
|
|
@ -61,15 +60,8 @@ async def test_init():
|
|||
},
|
||||
]
|
||||
|
||||
env = os.environ.copy()
|
||||
for i in inputs:
|
||||
seed = Inputs(**i)
|
||||
os.environ.clear()
|
||||
os.environ.update(env)
|
||||
CONFIG = Config()
|
||||
CONFIG.set_context(seed.kwargs)
|
||||
print(CONFIG.options)
|
||||
assert bool("language" in seed.kwargs) == bool("language" in CONFIG.options)
|
||||
|
||||
teacher = Teacher(
|
||||
name=seed.name,
|
||||
|
|
@ -105,7 +97,8 @@ async def test_new_file_name():
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run():
|
||||
CONFIG.set_context({"language": "Chinese", "teaching_language": "English"})
|
||||
context.kwargs.language = "Chinese"
|
||||
context.kwargs.teaching_language = "English"
|
||||
lesson = """
|
||||
UNIT 1 Making New Friends
|
||||
TOPIC 1 Welcome to China!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue