mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
refine tests
This commit is contained in:
parent
10cae23501
commit
f182b290cc
4 changed files with 16 additions and 14 deletions
|
|
@ -82,11 +82,13 @@ class RunCode(Action):
|
|||
llm: BaseLLM = Field(default_factory=LLM)
|
||||
|
||||
@classmethod
|
||||
@handle_exception
|
||||
async def run_text(cls, code) -> Tuple[str, str]:
|
||||
# We will document_store the result in this dictionary
|
||||
namespace = {}
|
||||
exec(code, namespace)
|
||||
try:
|
||||
# We will document_store the result in this dictionary
|
||||
namespace = {}
|
||||
exec(code, namespace)
|
||||
except Exception as e:
|
||||
return "", str(e)
|
||||
return namespace.get("result", ""), ""
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@ from metagpt.schema import RunCodeContext
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_text():
|
||||
result, errs = await RunCode.run_text("result = 1 + 1")
|
||||
assert result == 2
|
||||
assert errs == ""
|
||||
out, err = await RunCode.run_text("result = 1 + 1")
|
||||
assert out == 2
|
||||
assert err == ""
|
||||
|
||||
result, errs = await RunCode.run_text("result = 1 / 0")
|
||||
assert result == ""
|
||||
assert "ZeroDivisionError" in errs
|
||||
out, err = await RunCode.run_text("result = 1 / 0")
|
||||
assert out == ""
|
||||
assert "division by zero" in err
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
|
|
@ -63,9 +63,9 @@ async def test_react():
|
|||
assert role._rc.watch == {any_to_str(UserRequirement)}
|
||||
assert role.name == seed.name
|
||||
assert role.profile == seed.profile
|
||||
assert role._setting.goal == seed.goal
|
||||
assert role._setting.constraints == seed.constraints
|
||||
assert role._setting.desc == seed.desc
|
||||
assert role.goal == seed.goal
|
||||
assert role.constraints == seed.constraints
|
||||
assert role.desc == seed.desc
|
||||
assert role.is_idle
|
||||
env = Environment()
|
||||
env.add_role(role)
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@ def test_team():
|
|||
company = Team()
|
||||
company.hire([ProjectManager()])
|
||||
|
||||
assert len(company.environment.roles) == 1
|
||||
assert len(company.env.roles) == 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue