mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-20 15:38:09 +02:00
update: format directory structure and extract universal file operation class
This commit is contained in:
parent
473baf193c
commit
d83d1e105c
6 changed files with 102 additions and 59 deletions
|
|
@ -7,10 +7,9 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
import aiofiles
|
||||
import pytest
|
||||
|
||||
from metagpt.actions.write_tutorial import WriteDirectory, WriteContent, SaveDocx
|
||||
from metagpt.actions.write_tutorial import WriteDirectory, WriteContent
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -27,6 +26,7 @@ async def test_write_directory(language: str, topic: str):
|
|||
assert len(ret["directory"])
|
||||
assert isinstance(ret["directory"][0], dict)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
("language", "topic", "directory"),
|
||||
|
|
@ -38,16 +38,3 @@ async def test_write_content(language: str, topic: str, directory: Dict):
|
|||
assert list(directory.keys())[0] in ret
|
||||
for value in list(directory.values())[0]:
|
||||
assert value in ret
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
("title", "content"),
|
||||
[("Python", "Write a tutorial about Python")]
|
||||
)
|
||||
async def test_save_docx(title: str, content: str):
|
||||
ret = await SaveDocx().run(title=title, content=content)
|
||||
assert isinstance(ret, str)
|
||||
assert title in ret
|
||||
async with aiofiles.open(ret, mode="r") as reader:
|
||||
body = await reader.read()
|
||||
assert body == content
|
||||
27
tests/metagpt/utils/test_file.py
Normal file
27
tests/metagpt/utils/test_file.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env python3
|
||||
# _*_ coding: utf-8 _*_
|
||||
"""
|
||||
@Time : 2023/9/4 15:40:40
|
||||
@Author : Stitch-z
|
||||
@File : test_file.py
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
import aiofiles
|
||||
import pytest
|
||||
|
||||
from metagpt.utils.file import File
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
("root_path", "filename", "content"),
|
||||
[(Path("/code/MetaGPT/data/tutorial_docx/2023-09-07_17-05-20"), "test.md", "Hello World!")]
|
||||
)
|
||||
async def test_write_file(root_path: Path, filename: str, content: bytes):
|
||||
full_file_name = await File.write(root_path=root_path, filename=filename, content=content.encode('utf-8'))
|
||||
assert isinstance(full_file_name, Path)
|
||||
assert root_path / filename == full_file_name
|
||||
async with aiofiles.open(full_file_name, mode="r") as reader:
|
||||
body = await reader.read()
|
||||
assert body == content
|
||||
Loading…
Add table
Add a link
Reference in a new issue