mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-27 14:25:20 +02:00
feat: +pylint class view
This commit is contained in:
parent
81b1e5bb1c
commit
863a30e903
12 changed files with 528 additions and 98 deletions
24
tests/metagpt/actions/test_rebuild_class_view.py
Normal file
24
tests/metagpt/actions/test_rebuild_class_view.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Time : 2023/12/20
|
||||
@Author : mashenquan
|
||||
@File : test_rebuild_class_view.py
|
||||
@Desc : Unit tests for rebuild_class_view.py
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.actions.rebuild_class_view import RebuildClassView
|
||||
from metagpt.llm import LLM
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_rebuild():
|
||||
action = RebuildClassView(name="RedBean", context=Path(__file__).parent.parent, llm=LLM())
|
||||
await action.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-s"])
|
||||
0
tests/metagpt/test_repo_parser.py
Normal file
0
tests/metagpt/test_repo_parser.py
Normal file
|
|
@ -14,9 +14,8 @@ from pydantic import BaseModel
|
|||
|
||||
from metagpt.const import DEFAULT_WORKSPACE_ROOT
|
||||
from metagpt.repo_parser import RepoParser
|
||||
from metagpt.utils.common import concat_namespace
|
||||
from metagpt.utils.di_graph_repository import DiGraphRepository
|
||||
from metagpt.utils.graph_repository import GraphKeyword
|
||||
from metagpt.utils.graph_repository import GraphRepository
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -57,23 +56,7 @@ async def test_js_parser():
|
|||
repo_parser = RepoParser(base_directory=data.path)
|
||||
symbols = repo_parser.generate_symbols()
|
||||
for s in symbols:
|
||||
ns = s.get("file", "")
|
||||
for c in s.get("classes", []):
|
||||
await graph.insert(
|
||||
subject=concat_namespace(ns, c), predicate=GraphKeyword.IS.value, object_=GraphKeyword.CLASS.value
|
||||
)
|
||||
for f in s.get("functions", []):
|
||||
await graph.insert(
|
||||
subject=concat_namespace(ns, f),
|
||||
predicate=GraphKeyword.IS.value,
|
||||
object_=GraphKeyword.FUNCTION.value,
|
||||
)
|
||||
for g in s.get("globals", []):
|
||||
await graph.insert(
|
||||
subject=concat_namespace(ns, g),
|
||||
predicate=GraphKeyword.IS.value,
|
||||
object_=GraphKeyword.GLOBAL_VARIABLE.value,
|
||||
)
|
||||
await GraphRepository.update_graph_db(graph_db=graph, file_info=s)
|
||||
data = graph.json()
|
||||
assert data
|
||||
|
||||
|
|
@ -85,35 +68,14 @@ async def test_codes():
|
|||
|
||||
graph = DiGraphRepository(name="test", root=path)
|
||||
symbols = repo_parser.generate_symbols()
|
||||
for s in symbols:
|
||||
ns = s.get("file", "")
|
||||
for c in s.get("classes", []):
|
||||
class_name = c.get("name", "")
|
||||
await graph.insert(
|
||||
subject=ns, predicate=GraphKeyword.HAS_CLASS.value, object_=concat_namespace(ns, class_name)
|
||||
)
|
||||
await graph.insert(
|
||||
subject=concat_namespace(ns, class_name),
|
||||
predicate=GraphKeyword.IS.value,
|
||||
object_=GraphKeyword.CLASS.value,
|
||||
)
|
||||
methods = c.get("methods", [])
|
||||
for fn in methods:
|
||||
await graph.insert(
|
||||
subject=concat_namespace(ns, class_name, fn),
|
||||
predicate=GraphKeyword.IS.value,
|
||||
object_=GraphKeyword.CLASS_FUNCTION.value,
|
||||
)
|
||||
for f in s.get("functions", []):
|
||||
await graph.insert(
|
||||
subject=concat_namespace(ns, f), predicate=GraphKeyword.IS.value, object_=GraphKeyword.FUNCTION.value
|
||||
)
|
||||
for g in s.get("globals", []):
|
||||
await graph.insert(
|
||||
subject=concat_namespace(ns, g),
|
||||
predicate=GraphKeyword.IS.value,
|
||||
object_=GraphKeyword.GLOBAL_VARIABLE.value,
|
||||
)
|
||||
for file_info in symbols:
|
||||
for code_block in file_info.page_info:
|
||||
try:
|
||||
val = code_block.json(ensure_ascii=False)
|
||||
assert val
|
||||
except TypeError as e:
|
||||
assert not e
|
||||
await GraphRepository.update_graph_db(graph_db=graph, file_info=file_info)
|
||||
data = graph.json()
|
||||
assert data
|
||||
print(data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue