mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-26 09:16:21 +02:00
fixbug: make unit test stable
This commit is contained in:
parent
e0191c9b3d
commit
f4c6e507c9
1 changed files with 48 additions and 1 deletions
|
|
@ -8,6 +8,17 @@
|
|||
from pathlib import Path
|
||||
|
||||
import 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 config
|
||||
from metagpt.const import API_QUESTIONS_PATH, UT_PY_PATH
|
||||
|
|
@ -16,7 +27,43 @@ from metagpt.tools.ut_writer import YFT_PROMPT_PREFIX, UTGenerator
|
|||
|
||||
class 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)
|
||||
|
||||
# Prerequisites
|
||||
swagger_file = Path(__file__).parent / "../../data/ut_writer/yft_swaggerApi.json"
|
||||
assert swagger_file.exists()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue