-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: unit test of task.py #456
Open
LaiosOvO
wants to merge
1
commit into
petercat-ai:main
Choose a base branch
from
LaiosOvO:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
from unittest import TestCase | ||
|
||
from petercat_utils import task | ||
|
||
from github import Github | ||
|
||
from petercat_utils.data_class import RAGGitDocConfig , TaskType | ||
from petercat_utils.db.client.supabase import get_client | ||
from petercat_utils.rag_helper import git_doc_task | ||
|
||
from petercat_utils import retrieval | ||
|
||
g = Github() | ||
|
||
repo_name = "opendilab/CleanS2S" | ||
|
||
def convert_to_dict(task): | ||
return { | ||
"commit_id": task.commit_id, | ||
"node_type": task.node_type.value, | ||
"sha": task.sha, | ||
"path": task.path, | ||
"repo_name": task.repo_name, | ||
"status": task.status, | ||
"type": task.type, | ||
"from_id": task.from_id, | ||
"id": task.id, | ||
} | ||
|
||
def mock_rag_task(repo_name: str, bot_id: str): | ||
try: | ||
repo = g.get_repo(repo_name) | ||
default_branch = repo.default_branch | ||
config = RAGGitDocConfig( | ||
repo_name=repo_name, | ||
branch=default_branch, | ||
bot_id=bot_id, | ||
file_path="", | ||
commit_id="", | ||
) | ||
return git_doc_task.add_rag_git_doc_task(config) | ||
except Exception as e: | ||
print(f"trigger_rag_task error: {e}") | ||
|
||
|
||
def mock_bot(): | ||
repo = g.get_repo(repo_name) | ||
|
||
bot_data = { | ||
"name": repo_name, | ||
"description": "", | ||
"avatar": repo.organization.avatar_url if repo.organization else None, | ||
"prompt": "", | ||
"uid": "-1", | ||
"label": "Assistant", | ||
"starters": ( | ||
), | ||
"public": False, | ||
"hello_message": ( ), | ||
"repo_name": repo_name, | ||
"llm": "openai", | ||
"token_id": "" | ||
} | ||
res = get_client().table("bots").insert(bot_data).execute() | ||
|
||
print(res) | ||
return res.data[0] | ||
|
||
class TestTask(TestCase): | ||
repo_name = repo_name | ||
|
||
def setUp(self): | ||
# mock a bot record | ||
res = mock_bot() | ||
print(res) | ||
self.bot_id = res["id"] | ||
# mock the rag task of this bot | ||
res = mock_rag_task(self.repo_name, self.bot_id) | ||
res = res.data[0] | ||
self.task_id = res["id"] | ||
print(res) | ||
|
||
def test_send_message(self): | ||
from uuid import uuid4 | ||
res = task.send_task_message(uuid4().__str__()) | ||
print(res) | ||
|
||
def test_get_old_rag_task(self): | ||
res = task.get_oldest_task() | ||
print(res) | ||
|
||
|
||
def test_get_task_by_id(self): | ||
res = task.get_task_by_id(self.task_id) | ||
print(res) | ||
|
||
|
||
def test_get_task_doc(self): | ||
type = TaskType.GIT_DOC | ||
res = task.get_task(type, self.task_id) | ||
res = convert_to_dict(res) | ||
print(res) | ||
|
||
|
||
def test_trigger_task_type_doc(self): | ||
type = TaskType.GIT_DOC | ||
res = task.trigger_task(type, self.task_id) | ||
print(res) | ||
|
||
|
||
def test_single_message_handle_lambda_function_handle(self): | ||
type = TaskType.GIT_DOC | ||
res = task.trigger_task(type, self.task_id) | ||
print(res) | ||
|
||
res = (get_client() | ||
.table("rag_tasks") | ||
.select("*") | ||
.eq("repo_name", self.repo_name) | ||
.execute()) | ||
print(res) | ||
blob_node = [node for node in res.data if node['node_type'] == 'BLOB'] | ||
res = blob_node[0] | ||
print(res) | ||
|
||
# save blob file to chunkList | ||
res.handle() | ||
if res["node_type"] == "blob": | ||
chunkList = retrieval.get_chunk_list(self.repo_name, 1, 10) | ||
if chunkList: | ||
self.assertTrue(chunkList["total"] > 0) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
res.handle()
method is called on line 127, but it is unclear what this method does or if it exists. Ensure thatres
has ahandle
method and that it is being used correctly. If this is a mock or a stub, consider providing a more explicit implementation or a comment explaining its purpose.