add test document

This commit is contained in:
geekan 2024-01-02 21:07:03 +08:00
parent 66d3e8448d
commit 54201b1459
3 changed files with 55 additions and 24 deletions

View file

@ -20,8 +20,6 @@ from langchain.text_splitter import CharacterTextSplitter
from pydantic import BaseModel, ConfigDict, Field
from tqdm import tqdm
from metagpt.config import CONFIG
from metagpt.logs import logger
from metagpt.repo_parser import RepoParser
@ -213,7 +211,7 @@ class Repo(BaseModel):
self.assets[path] = doc
return doc
def set(self, content: str, filename: str):
def set(self, filename: str, content: str):
"""Set a document and persist it to disk."""
path = self._path(filename)
doc = self._set(content, path)
@ -232,24 +230,3 @@ class Repo(BaseModel):
n_chars = sum(sum(len(j.content) for j in i.values()) for i in [self.docs, self.codes, self.assets])
symbols = RepoParser(base_directory=self.path).generate_symbols()
return RepoMetadata(name=self.name, n_docs=n_docs, n_chars=n_chars, symbols=symbols)
def set_existing_repo(path=CONFIG.workspace_path / "t1"):
repo1 = Repo.from_path(path)
repo1.set("wtf content", "doc/wtf_file.md")
repo1.set("wtf code", "code/wtf_file.py")
logger.info(repo1) # check doc
def load_existing_repo(path=CONFIG.workspace_path / "web_tetris"):
repo = Repo.from_path(path)
logger.info(repo)
logger.info(repo.eda())
def main():
load_existing_repo()
if __name__ == "__main__":
main()

View file

@ -5,6 +5,8 @@
@Author : alexanderwu
@File : test_action.py
"""
import pytest
from metagpt.actions import Action, ActionType, WritePRD, WriteTest
@ -18,3 +20,22 @@ def test_action_type():
assert ActionType.WRITE_TEST.value == WriteTest
assert ActionType.WRITE_PRD.name == "WRITE_PRD"
assert ActionType.WRITE_TEST.name == "WRITE_TEST"
def test_simple_action():
action = Action(name="AlexSay", instruction="Express your opinion with emotion and don't repeat it")
assert action.name == "AlexSay"
assert action.node.instruction == "Express your opinion with emotion and don't repeat it"
def test_empty_action():
action = Action()
assert action.name == "Action"
assert not action.node
@pytest.mark.asyncio
async def test_empty_action_exception():
action = Action()
with pytest.raises(NotImplementedError):
await action.run()

View file

@ -0,0 +1,33 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 2024/1/2 21:00
@Author : alexanderwu
@File : test_document.py
"""
from metagpt.config import CONFIG
from metagpt.document import Repo
from metagpt.logs import logger
def set_existing_repo(path):
repo1 = Repo.from_path(path)
repo1.set("doc/wtf_file.md", "wtf content")
repo1.set("code/wtf_file.py", "def hello():\n print('hello')")
logger.info(repo1) # check doc
def load_existing_repo(path):
repo = Repo.from_path(path)
logger.info(repo)
logger.info(repo.eda())
assert repo
assert repo.get("doc/wtf_file.md").content == "wtf content"
assert repo.get("code/wtf_file.py").content == "def hello():\n print('hello')"
def test_repo_set_load():
repo_path = CONFIG.workspace_path / "test_repo"
set_existing_repo(repo_path)
load_existing_repo(repo_path)