From fd11f46587c98bdca67773b289f75dd9c5d1b7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Mon, 8 Jan 2024 15:19:16 +0800 Subject: [PATCH] fixbug: unit test --- tests/metagpt/actions/test_skill_action.py | 8 ++++++-- tests/metagpt/learn/test_text_to_image.py | 10 +++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/metagpt/actions/test_skill_action.py b/tests/metagpt/actions/test_skill_action.py index 0e0d5d5aa..69cd8129d 100644 --- a/tests/metagpt/actions/test_skill_action.py +++ b/tests/metagpt/actions/test_skill_action.py @@ -47,7 +47,10 @@ 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 + mocker.patch("metagpt.learn.text_to_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 +83,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