feat: replace global CONTEXT with Config()

fixbug: unit test
This commit is contained in:
莘权 马 2024-01-22 17:13:20 +08:00
parent ff314388bb
commit e8b3e6762b
15 changed files with 44 additions and 33 deletions

BIN
tests/data/audio/hello.mp3 Normal file

Binary file not shown.

View file

@ -99,7 +99,7 @@ def test_parse_code():
def test_todo():
role = Engineer()
assert role.todo == any_to_name(WriteCode)
assert role.action_description == any_to_name(WriteCode)
@pytest.mark.asyncio

View file

@ -144,3 +144,7 @@ async def test_team_recover_multi_roles_save(mocker, context):
assert new_company.env.get_role(role_b.profile).rc.state == 1
await new_company.run(n_round=4)
if __name__ == "__main__":
pytest.main([__file__, "-s"])

View file

@ -6,7 +6,7 @@
@File : test_context.py
"""
from metagpt.configs.llm_config import LLMType
from metagpt.context import CONTEXT, AttrDict, Context
from metagpt.context import AttrDict, Context
def test_attr_dict_1():
@ -51,11 +51,12 @@ def test_context_1():
def test_context_2():
llm = CONTEXT.config.get_openai_llm()
ctx = Context()
llm = ctx.config.get_openai_llm()
assert llm is not None
assert llm.api_type == LLMType.OPENAI
kwargs = CONTEXT.kwargs
kwargs = ctx.kwargs
assert kwargs is not None
kwargs.test_key = "test_value"

View file

@ -11,7 +11,6 @@ from pathlib import Path
import pytest
from metagpt.actions import UserRequirement
from metagpt.context import CONTEXT
from metagpt.environment import Environment
from metagpt.logs import logger
from metagpt.roles import Architect, ProductManager, Role
@ -44,9 +43,9 @@ def test_get_roles(env: Environment):
@pytest.mark.asyncio
async def test_publish_and_process_message(env: Environment):
if CONTEXT.git_repo:
CONTEXT.git_repo.delete_repository()
CONTEXT.git_repo = None
if env.context.git_repo:
env.context.git_repo.delete_repository()
env.context.git_repo = None
product_manager = ProductManager(name="Alice", profile="Product Manager", goal="做AI Native产品", constraints="资源有限")
architect = Architect(

View file

@ -131,7 +131,7 @@ async def test_recover():
role.recovered = True
role.latest_observed_msg = Message(content="recover_test")
role.rc.state = 0
assert role.first_action == any_to_name(MockAction)
assert role.action_description == any_to_name(MockAction)
rsp = await role.run()
assert rsp.cause_by == any_to_str(MockAction)