Skip to content

Commit

Permalink
Add test for codeanalysis tools (#644)
Browse files Browse the repository at this point in the history
Co-authored-by: Viraj <35092918+angrybayblade@users.noreply.github.com>
  • Loading branch information
shreysingla11 and angrybayblade authored Sep 27, 2024
1 parent 14cd0af commit f65dbc7
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 2 deletions.
1 change: 1 addition & 0 deletions python/composio/client/enums/_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -2210,6 +2210,7 @@ class Action(_AnnotatedEnum[ActionData], path=ACTIONS_CACHE):
GMAIL_GET_ATTACHMENT: "Action"
GMAIL_LIST_LABELS: "Action"
GMAIL_LIST_THREADS: "Action"
GMAIL_REMOVE_LABEL: "Action"
GMAIL_REPLY_TO_THREAD: "Action"
GMAIL_SEND_EMAIL: "Action"
GOOGLECALENDAR_CREATE_EVENT: "Action"
Expand Down
2 changes: 2 additions & 0 deletions python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import os
import typing as t
from pathlib import Path

import pytest


IS_CI = os.environ.get("CI") == "true"
E2E = pytest.mark.e2e
ROOT_DIR = Path(__file__).parent.parent


def skip_if_ci(reason: str) -> t.Callable:
Expand Down
137 changes: 137 additions & 0 deletions python/tests/test_tools/test_local/test_codeanalysistool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import json

from composio.tools.local.codeanalysis.actions.create_codemap import (
CreateCodeMap,
CreateCodeMapRequest,
)
from composio.tools.local.codeanalysis.actions.get_class_info import (
GetClassInfo,
GetClassInfoRequest,
)
from composio.tools.local.codeanalysis.actions.get_method_body import (
GetMethodBody,
GetMethodBodyRequest,
)
from composio.tools.local.codeanalysis.actions.get_method_signature import (
GetMethodSignature,
GetMethodSignatureRequest,
)
from composio.tools.local.codeanalysis.actions.get_relevant_code import (
GetRelevantCode,
GetRelevantCodeRequest,
)

from tests.conftest import ROOT_DIR


class TestCodeAnalysisTool:
repo_path = ROOT_DIR / "composio/cli/"

@classmethod
def setup_class(cls):
create_codemap = CreateCodeMap()
response = create_codemap.execute(
CreateCodeMapRequest(), metadata={"dir_to_index_path": cls.repo_path}
)
assert "Indexing completed" in str(
response.result
) or "Indexing already exists" in str(response.result)

def test_create_codemap(self):
with (self.repo_path / ".indexing_status.json").open("r") as f:
status = json.load(f)
assert status["status"] == "completed"

def test_get_class_info(self):
get_class_info = GetClassInfo()
response = get_class_info.execute(
GetClassInfoRequest(class_name="UpdateExamples"),
metadata={"dir_to_index_path": self.repo_path},
)
assert "UpdateExamples" in str(response.result)
assert "apps.py" in str(response.result)

response = get_class_info.execute(
GetClassInfoRequest(class_name="SomeRandomClass"),
metadata={"dir_to_index_path": self.repo_path},
)
assert "No matching" in str(response.result)

def test_get_method_signature(self):
get_method_signature = GetMethodSignature()
response = get_method_signature.execute(
GetMethodSignatureRequest(method_name="_update_apps"),
metadata={"dir_to_index_path": self.repo_path},
)
assert "_update_apps" in str(response.result)
assert "apps.py" in str(response.result)
assert "Not a member of any class" in str(response.result)

response = get_method_signature.execute(
GetMethodSignatureRequest(
class_name="HelpfulCmdBase", method_name="format_help_text"
),
metadata={"dir_to_index_path": self.repo_path},
)
assert "HelpfulCmdBase" in str(response.result)
assert "helpfulcmd.py" in str(response.result)
assert "format_help_text" in str(response.result)

response = get_method_signature.execute(
GetMethodSignatureRequest(
class_name="SomeRandomClass", method_name="format_help_text"
),
metadata={"dir_to_index_path": self.repo_path},
)
assert "No matching methods found" in str(response.result)

response = get_method_signature.execute(
GetMethodSignatureRequest(
class_name="SomeRandomClass", method_name="some_random_method"
),
metadata={"dir_to_index_path": self.repo_path},
)
assert "No matching methods found" in str(response.result)

def test_get_method_body(self):
get_method_body = GetMethodBody()
response = get_method_body.execute(
GetMethodBodyRequest(method_name="_update_apps"),
metadata={"dir_to_index_path": self.repo_path},
)
assert "```python" in str(response.result)
assert "_update_apps" in str(response.result)

response = get_method_body.execute(
GetMethodBodyRequest(
class_name="HelpfulCmdBase", method_name="format_help_text"
),
metadata={"dir_to_index_path": self.repo_path},
)
assert "```python" in str(response.result)
assert "format_help_text" in str(response.result)

response = get_method_body.execute(
GetMethodBodyRequest(
class_name="SomeRandomClass", method_name="format_help_text"
),
metadata={"dir_to_index_path": self.repo_path},
)
assert "No matching methods found" in str(response.result)

response = get_method_body.execute(
GetMethodBodyRequest(
class_name="SomeRandomClass", method_name="some_random_method"
),
metadata={"dir_to_index_path": self.repo_path},
)
assert "No matching methods found" in str(response.result)

def test_get_relevant_code(self):
get_relevant_code = GetRelevantCode()
response = get_relevant_code.execute(
GetRelevantCodeRequest(query="How to update apps?"),
metadata={"dir_to_index_path": self.repo_path},
)
assert "How to update apps?" in str(response.result)
assert "Chunk" in str(response.result)
4 changes: 2 additions & 2 deletions python/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ deps =
codecov==2.1.13
pytest-codecov==0.5.1
typing_extensions==4.10.0
tree_sitter # codeanalysis
tree_sitter==0.21.3# codeanalysis
deeplake # codeanalysis
jedi # codeanalysis
git+https://github.com/DataDog/jedi.git@92d0c807b0dcd115b1ffd0a4ed21e44db127c2fb#egg=jedi # codeanalysis
libcst # codeanalysis
sentence_transformers # codeanalysis
tree_sitter_languages # codeanalysis
Expand Down

0 comments on commit f65dbc7

Please sign in to comment.