mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-23 15:48:11 +02:00
feature: aioboto3 client
This commit is contained in:
parent
a36d46d6b9
commit
478139c8dc
5 changed files with 198 additions and 3 deletions
|
|
@ -9,7 +9,6 @@
|
|||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from metagpt.config import Config
|
||||
from metagpt.logs import logger
|
||||
|
|
@ -17,6 +16,8 @@ from metagpt.provider.openai_api import OpenAIGPTAPI as GPTAPI
|
|||
import asyncio
|
||||
import re
|
||||
|
||||
from metagpt.utils.s3 import S3
|
||||
|
||||
|
||||
class Context:
|
||||
def __init__(self):
|
||||
|
|
@ -74,3 +75,7 @@ def proxy():
|
|||
@pytest.fixture(scope="session", autouse=True)
|
||||
def init_config():
|
||||
Config()
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def s3():
|
||||
return S3()
|
||||
|
|
|
|||
55
tests/metagpt/utils/test_s3.py
Normal file
55
tests/metagpt/utils/test_s3.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import os
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
["bucket", "local_path", "object_name"],
|
||||
[
|
||||
(
|
||||
"agent-store",
|
||||
"/code/send18-MetaGPT/workspace/resources/SD_Output/Flappy Bird_output_0.png",
|
||||
"ui-designer/2023-09-01/1.png"
|
||||
)
|
||||
]
|
||||
)
|
||||
async def test_upload_file(s3, bucket, local_path, object_name):
|
||||
await s3.upload_file(bucket=bucket, local_path=local_path, object_name=object_name)
|
||||
s3_object = await s3.get_object(bucket=bucket, object_name=object_name)
|
||||
assert s3_object
|
||||
assert isinstance(s3_object, bytes)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
["bucket", "object_name"],
|
||||
[("agent-store", "ui-designer/2023-09-01/1.png")]
|
||||
)
|
||||
async def test_get_object_url(s3, bucket, object_name):
|
||||
url = await s3.get_object_url(bucket=bucket, object_name=object_name)
|
||||
assert bucket in url
|
||||
assert object_name in url
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
["bucket", "object_name"],
|
||||
[("agent-store", "ui-designer/2023-09-01/1.png")]
|
||||
)
|
||||
async def test_get_object(s3, bucket, object_name):
|
||||
s3_object = await s3.get_object(bucket=bucket, object_name=object_name)
|
||||
assert s3_object
|
||||
assert isinstance(s3_object, bytes)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
["bucket", "local_path", "object_name"],
|
||||
[
|
||||
(
|
||||
"agent-store",
|
||||
"/code/send18-MetaGPT/workspace/resources/SD_Output/Flappy Bird_output_0.png",
|
||||
"ui-designer/2023-09-01/1.png"
|
||||
)
|
||||
]
|
||||
)
|
||||
async def test_download_file(s3, bucket, local_path, object_name):
|
||||
await s3.download_file(bucket=bucket, object_name=object_name, local_path=local_path)
|
||||
assert os.path.exists(local_path)
|
||||
Loading…
Add table
Add a link
Reference in a new issue