🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
fixbug: make unit test stable
莘权 马f4c6e507c9d2
diff --git a/tests/metagpt/tools/test_ut_writer.py b/tests/metagpt/tools/test_ut_writer.pyindex 29b6572c2..3cc7e86bb 100644--- a/tests/metagpt/tools/test_ut_writer.py+++ b/tests/metagpt/tools/test_ut_writer.py@@ -8,6 +8,17 @@from pathlib import Pathimport pytest+from openai.resources.chat.completions import AsyncCompletions+from openai.types import CompletionUsage+from openai.types.chat.chat_completion import (+ ChatCompletion,+ ChatCompletionMessage,+ Choice,+)+from openai.types.chat.chat_completion_message_tool_call import (+ ChatCompletionMessageToolCall,+ Function,+)from metagpt.config2 import configfrom metagpt.const import API_QUESTIONS_PATH, UT_PY_PATH@@ -16,7 +27,43 @@ from metagpt.tools.ut_writer import YFT_PROMPT_PREFIX, UTGeneratorclass TestUTWriter:@pytest.mark.asyncio- async def test_api_to_ut_sample(self):+ async def test_api_to_ut_sample(self, mocker):+ async def mock_create(*args, **kwargs):+ return ChatCompletion(+ id="chatcmpl-8n5fAd21w2J1IIFkI4qxWlNfM7QRC",+ choices=[+ Choice(+ finish_reason="stop",+ index=0,+ logprobs=None,+ message=ChatCompletionMessage(+ content=None,+ role="assistant",+ function_call=None,+ tool_calls=[+ ChatCompletionMessageToolCall(+ id="call_EjjmIY7GMspHu3r9mx8gPA2k",+ function=Function(+ arguments='{"code":"import string\\nimport random\\n\\ndef random_string'+ "(length=10):\\n return ''.join(random.choice(string.ascii_"+ 'lowercase) for i in range(length))"}',+ name="execute",+ ),+ type="function",+ )+ ],+ ),+ )+ ],+ created=1706710532,+ model="gpt-3.5-turbo-1106",+ object="chat.completion",+ system_fingerprint="fp_04f9a1eebf",+ usage=CompletionUsage(completion_tokens=35, prompt_tokens=1982, total_tokens=2017),+ )++ mocker.patch.object(AsyncCompletions, "create", mock_create)+# Prerequisitesswagger_file = Path(__file__).parent / "../../data/ut_writer/yft_swaggerApi.json"assert swagger_file.exists()