mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-11 15:15:18 +02:00
add test document
This commit is contained in:
parent
66d3e8448d
commit
54201b1459
3 changed files with 55 additions and 24 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
33
tests/metagpt/test_document.py
Normal file
33
tests/metagpt/test_document.py
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue