fixbug: unit test

This commit is contained in:
莘权 马 2024-01-08 14:45:23 +08:00
parent f445dacb8a
commit 7f04eaafae
3 changed files with 18 additions and 3 deletions

View file

@ -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__":

View file

@ -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