mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-12 01:02:37 +02:00
feat: +unit test
This commit is contained in:
parent
5510df5f96
commit
681068edc9
27 changed files with 357 additions and 548 deletions
|
|
@ -528,18 +528,18 @@ def role_raise_decorator(func):
|
|||
|
||||
|
||||
@handle_exception
|
||||
async def aread(file_path: str) -> str:
|
||||
async def aread(filename: str | Path, encoding=None) -> str:
|
||||
"""Read file asynchronously."""
|
||||
async with aiofiles.open(str(file_path), mode="r") as reader:
|
||||
async with aiofiles.open(str(filename), mode="r", encoding=encoding) as reader:
|
||||
content = await reader.read()
|
||||
return content
|
||||
|
||||
|
||||
async def awrite(filename: str | Path, data: str):
|
||||
async def awrite(filename: str | Path, data: str, encoding=None):
|
||||
"""Write file asynchronously."""
|
||||
pathname = Path(filename)
|
||||
pathname.parent.mkdir(parents=True, exist_ok=True)
|
||||
async with aiofiles.open(str(pathname), mode="w", encoding="utf-8") as writer:
|
||||
async with aiofiles.open(str(pathname), mode="w", encoding=encoding) as writer:
|
||||
await writer.write(data)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue