Skip to content

Commit

Permalink
Merge pull request #76 from rofrano/fix-testcases
Browse files Browse the repository at this point in the history
Added test cases for PythonSitter and Python Analysis
  • Loading branch information
rahlk authored Jan 29, 2025
2 parents 54f6644 + e1e7c52 commit 8d118d9
Show file tree
Hide file tree
Showing 5 changed files with 517 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cldk/analysis/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
Python package
"""

from .python import PythonAnalysis
from .python_analysis import PythonAnalysis

__all__ = ["PythonAnalysis"]
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
Python module
"""

from abc import ABC
from pathlib import Path
from typing import Dict, List
from pandas import DataFrame
from typing import List

from cldk.analysis import SymbolTable
from cldk.analysis.python.treesitter import PythonSitter
from cldk.models.python.models import PyMethod, PyImport, PyModule, PyClass


class PythonAnalysis(SymbolTable):
"""Python Analysis Class"""

def __init__(
self,
analysis_backend: str,
Expand All @@ -48,13 +48,13 @@ def __init__(

# Initialize the analysis analysis_backend
if analysis_backend.lower() == "codeql":
raise NotImplementedError(f"Support for {analysis_backend} has not been implemented yet.")
raise NotImplementedError("Support for {analysis_backend} has not been implemented yet.")
elif analysis_backend.lower() == "codeanalyzer":
raise NotImplementedError(f"Support for {analysis_backend} has not been implemented yet.")
raise NotImplementedError("Support for {analysis_backend} has not been implemented yet.")
elif analysis_backend.lower() == "treesitter":
self.analysis_backend: PythonSitter = PythonSitter()
else:
raise NotImplementedError(f"Support for {analysis_backend} has not been implemented yet.")
raise NotImplementedError("Support for {analysis_backend} has not been implemented yet.")

def get_methods(self) -> List[PyMethod]:
"""
Expand Down Expand Up @@ -89,14 +89,14 @@ def get_method_details(self, method_signature: str) -> PyMethod:

def is_parsable(self, source_code: str) -> bool:
"""
Check if the code is parsable
Args:
source_code: source code
Check if the code is parsable
Args:
source_code: source code
Returns:
True if the code is parsable, False otherwise
Returns:
True if the code is parsable, False otherwise
"""
return PythonSitter.is_parsable(self, source_code)
return PythonSitter().is_parsable(source_code)

def get_raw_ast(self, source_code: str) -> str:
"""
Expand All @@ -107,9 +107,9 @@ def get_raw_ast(self, source_code: str) -> str:
Returns:
Tree: the raw AST
"""
return PythonSitter.get_raw_ast(self, source_code)
return PythonSitter().get_raw_ast(source_code)

def get_imports(self) -> List[PyImport]:
def get_imports(self) -> List[PyImport]:
"""
Given an application or a source code, get all the imports
"""
Expand All @@ -119,7 +119,7 @@ def get_variables(self, **kwargs):
"""
Given an application or a source code, get all the variables
"""
raise NotImplementedError(f"Support for this functionality has not been implemented yet.")
raise NotImplementedError("Support for this functionality has not been implemented yet.")

def get_classes(self) -> List[PyClass]:
"""
Expand All @@ -131,34 +131,34 @@ def get_classes_by_criteria(self, **kwargs):
"""
Given an application or a source code, get all the classes given the inclusion and exclution criteria
"""
raise NotImplementedError(f"Support for this functionality has not been implemented yet.")
raise NotImplementedError("Support for this functionality has not been implemented yet.")

def get_sub_classes(self, **kwargs):
"""
Given an application or a source code, get all the sub-classes
"""
raise NotImplementedError(f"Support for this functionality has not been implemented yet.")
raise NotImplementedError("Support for this functionality has not been implemented yet.")

def get_nested_classes(self, **kwargs):
"""
Given an application or a source code, get all the nested classes
"""
raise NotImplementedError(f"Support for this functionality has not been implemented yet.")
raise NotImplementedError("Support for this functionality has not been implemented yet.")

def get_constructors(self, **kwargs):
"""
Given an application or a source code, get all the constructors
"""
raise NotImplementedError(f"Support for this functionality has not been implemented yet.")
raise NotImplementedError("Support for this functionality has not been implemented yet.")

def get_methods_in_class(self, **kwargs):
"""
Given an application or a source code, get all the methods within the given class
"""
raise NotImplementedError(f"Support for this functionality has not been implemented yet.")
raise NotImplementedError("Support for this functionality has not been implemented yet.")

def get_fields(self, **kwargs):
"""
Given an application or a source code, get all the fields
"""
raise NotImplementedError(f"Support for this functionality has not been implemented yet.")
raise NotImplementedError("Support for this functionality has not been implemented yet.")
Empty file.
Loading

0 comments on commit 8d118d9

Please sign in to comment.