Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

fixbug: unit test

莘权 马7f04eaafae18
diff --git a/.gitignore b/.gitignore
index 6dd3608f1..a6f45d894 100644
--- a/.gitignore
+++ b/.gitignore
@@ -175,3 +175,4 @@ htmlcov.*
*.pkl
*-structure.csv
*-structure.json
+*.dot
\ No newline at end of file
diff --git a/tests/metagpt/actions/test_skill_action.py b/tests/metagpt/actions/test_skill_action.py
index 0e0d5d5aa..529ed632a 100644
--- a/tests/metagpt/actions/test_skill_action.py
+++ b/tests/metagpt/actions/test_skill_action.py
@@ -6,6 +6,7 @@
@File : test_skill_action.py
@Desc : Unit tests.
"""
+
import pytest
from metagpt.actions.skill_action import ArgumentsParingAction, SkillAction
@@ -47,7 +48,11 @@ class TestSkillAction:
assert args.get("size_type") == "512x512"
@pytest.mark.asyncio
- async def test_parser_action(self):
+ async def test_parser_action(self, mocker):
+ # mock
+ mock_text_2_image = mocker.patch("metagpt.learn.text_to_image")
+ mock_text_2_image.return_value = "https://mock.com/xxx"
+
parser_action = ArgumentsParingAction(skill=self.skill, ask="Draw an apple")
rsp = await parser_action.run()
assert rsp
@@ -80,7 +85,8 @@ class TestSkillAction:
@pytest.mark.asyncio
async def test_skill_action_error(self):
action = SkillAction(skill=self.skill, args={})
- await action.run()
+ rsp = await action.run()
+ assert "Error" in rsp.content
if __name__ == "__main__":
diff --git a/tests/metagpt/learn/test_text_to_image.py b/tests/metagpt/learn/test_text_to_image.py
index 760b9d09c..1485df5c6 100644
--- a/tests/metagpt/learn/test_text_to_image.py
+++ b/tests/metagpt/learn/test_text_to_image.py
@@ -12,10 +12,18 @@ import pytest
from metagpt.config import CONFIG
from metagpt.learn.text_to_image import text_to_image
+from metagpt.tools.metagpt_text_to_image import MetaGPTText2Image
+from metagpt.tools.openai_text_to_image import OpenAIText2Image
+from metagpt.utils.s3 import S3
@pytest.mark.asyncio
-async def test_metagpt_llm():
+async def test_text_to_image(mocker):
+ # mock
+ mocker.patch.object(MetaGPTText2Image, "text_2_image", return_value=b"mock MetaGPTText2Image")
+ mocker.patch.object(OpenAIText2Image, "text_2_image", return_value=b"mock OpenAIText2Image")
+ mocker.patch.object(S3, "cache", return_value="http://mock/s3")
+
# Prerequisites
assert CONFIG.METAGPT_TEXT_TO_IMAGE_MODEL_URL
assert CONFIG.OPENAI_API_KEY