Skip to content

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

fixbug: unit test

莘权 马8e7ea369df62
diff --git a/setup.py b/setup.py
index 42676c2e6..0439d6cd4 100644
--- a/setup.py
+++ b/setup.py
@@ -47,6 +47,7 @@ extras_require["test"] = [
"gradio==3.0.0",
"grpcio-status==1.48.2",
"mock==5.1.0",
+ "pylint==3.0.3",
]
extras_require["pyppeteer"] = [
diff --git a/tests/metagpt/actions/test_write_prd.py b/tests/metagpt/actions/test_write_prd.py
index 89b432fe2..6d943df5e 100644
--- a/tests/metagpt/actions/test_write_prd.py
+++ b/tests/metagpt/actions/test_write_prd.py
@@ -19,6 +19,7 @@ from metagpt.utils.file_repository import FileRepository
@pytest.mark.asyncio
@pytest.mark.usefixtures("llm_mock")
async def test_write_prd():
product_manager = ProductManager()
requirements = "开发一个基于大语言模型与私有知识库的搜索引擎,希望可以基于大语言模型进行搜索总结"
diff --git a/tests/metagpt/roles/test_teacher.py b/tests/metagpt/roles/test_teacher.py
index 4da860b51..d05283b6f 100644
--- a/tests/metagpt/roles/test_teacher.py
+++ b/tests/metagpt/roles/test_teacher.py
@@ -17,6 +17,7 @@ from metagpt.schema import Message
@pytest.mark.asyncio
async def test_init():
class Inputs(BaseModel):
name: str
diff --git a/tests/metagpt/tools/test_metagpt_text_to_image.py b/tests/metagpt/tools/test_metagpt_text_to_image.py
index f5ced2061..b765119f0 100644
--- a/tests/metagpt/tools/test_metagpt_text_to_image.py
+++ b/tests/metagpt/tools/test_metagpt_text_to_image.py
@@ -5,6 +5,8 @@
@Author : mashenquan
@File : test_metagpt_text_to_image.py
"""
+import base64
+from unittest.mock import AsyncMock
import pytest
@@ -13,7 +15,14 @@ from metagpt.tools.metagpt_text_to_image import oas3_metagpt_text_to_image
@pytest.mark.asyncio
-async def test_draw():
+async def test_draw(mocker):
+ # mock
+ mock_post = mocker.patch("aiohttp.ClientSession.post")
+ mock_response = AsyncMock()
+ mock_response.status = 200
+ mock_response.json.return_value = {"images": [base64.b64encode(b"success")], "parameters": {"size": 1110}}
+ mock_post.return_value.__aenter__.return_value = mock_response
+
# Prerequisites
assert CONFIG.METAGPT_TEXT_TO_IMAGE_MODEL_URL
diff --git a/tests/metagpt/utils/test_di_graph_repository.py b/tests/metagpt/utils/test_di_graph_repository.py
index 0a8011e51..966aaf1b0 100644
--- a/tests/metagpt/utils/test_di_graph_repository.py
+++ b/tests/metagpt/utils/test_di_graph_repository.py
@@ -56,7 +56,7 @@ async def test_js_parser():
repo_parser = RepoParser(base_directory=data.path)
symbols = repo_parser.generate_symbols()
for s in symbols:
- await GraphRepository.update_graph_db(graph_db=graph, file_info=s)
+ await GraphRepository.update_graph_db_with_file_info(graph_db=graph, file_info=s)
data = graph.json()
assert data
@@ -71,11 +71,11 @@ async def test_codes():
for file_info in symbols:
for code_block in file_info.page_info:
try:
- val = code_block.json(ensure_ascii=False)
+ val = code_block.model_dump_json()
assert val
except TypeError as e:
assert not e
- await GraphRepository.update_graph_db(graph_db=graph, file_info=file_info)
+ await GraphRepository.update_graph_db_with_file_info(graph_db=graph, file_info=file_info)
data = graph.json()
assert data
print(data)
diff --git a/tests/metagpt/utils/test_read_docx.py b/tests/metagpt/utils/test_read_docx.py
index adf473ae7..5680adb0f 100644
--- a/tests/metagpt/utils/test_read_docx.py
+++ b/tests/metagpt/utils/test_read_docx.py
@@ -5,11 +5,13 @@
@Author : alexanderwu
@File : test_read_docx.py
"""
+import pytest
from metagpt.const import METAGPT_ROOT
from metagpt.utils.read_document import read_docx
[email protected] # https://copyprogramming.com/howto/python-docx-error-opening-file-bad-magic-number-for-file-header-eoferror
class TestReadDocx:
def test_read_docx(self):
docx_sample = METAGPT_ROOT / "tests/data/docx_for_test.docx"