Skip to content

Fix Issue 104: Tests are failing upon migration to codeanalyzer v2.1.0+ #111

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

Merged
merged 8 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lint: ## Run the linter
.PHONY: test
test: ## Run the unit tests
$(info Running tests...)
pytest --pspec --cov=cldk --cov-fail-under=50 --disable-warnings
pytest --pspec --cov=cldk --cov-fail-under=70 --disable-warnings

##@ Build

Expand Down
50 changes: 25 additions & 25 deletions cldk/analysis/c/c_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

from pathlib import Path
from typing import Dict, List, Optional
import networkx as nx

from networkx import DiGraph

from cldk.analysis.c.clang import ClangAnalyzer
from cldk.models.c import CApplication, CFunction, CTranslationUnit, CMacro, CTypedef, CStruct, CEnum, CVariable
Expand Down Expand Up @@ -56,7 +56,7 @@ def _init_application(self, project_dir: Path) -> CApplication:
return CApplication(translation_units=translation_units)

def get_c_application(self) -> CApplication:
"""Returns the C application object.
"""returns the C application object.

Returns:
CApplication: C application object.
Expand Down Expand Up @@ -89,16 +89,16 @@ def is_parsable(self, source_code: str) -> bool:
"""
raise NotImplementedError("Support for this functionality has not been implemented yet.")

def get_call_graph(self) -> DiGraph:
"""Returns the call graph of the C code.
def get_call_graph(self) -> nx.DiGraph:
"""returns the call graph of the C code.

Returns:
DiGraph: The call graph of the C code.
nx.DiGraph: The call graph of the C code.
"""
raise NotImplementedError("Support for this functionality has not been implemented yet.")

def get_call_graph_json(self) -> str:
"""Returns a serialized call graph in json.
"""returns a serialized call graph in json.

Raises:
NotImplementedError: Raised when this functionality is not suported.
Expand All @@ -110,7 +110,7 @@ def get_call_graph_json(self) -> str:
raise NotImplementedError("Producing a call graph over a single file is not implemented yet.")

def get_callers(self, function: CFunction) -> Dict:
"""Returns a dictionary of callers of the target method.
"""returns a dictionary of callers of the target method.

Args:
function (CFunction): A CFunction object.
Expand All @@ -125,7 +125,7 @@ def get_callers(self, function: CFunction) -> Dict:
raise NotImplementedError("Generating all callers over a single file is not implemented yet.")

def get_callees(self, function: CFunction) -> Dict:
"""Returns a dictionary of callees in a fuction.
"""returns a dictionary of callees in a fuction.

Args:
function (CFunction): A CFunction object.
Expand All @@ -139,7 +139,7 @@ def get_callees(self, function: CFunction) -> Dict:
raise NotImplementedError("Generating all callees over a single file is not implemented yet.")

def get_functions(self) -> Dict[str, CFunction]:
"""Returns all functions in the project.
"""returns all functions in the project.

Raises:
NotImplementedError: Raised when current AnalysisEngine does not support this function.
Expand All @@ -151,7 +151,7 @@ def get_functions(self) -> Dict[str, CFunction]:
return translation_unit.functions

def get_function(self, function_name: str, file_name: Optional[str]) -> CFunction | List[CFunction]:
"""Returns a function object given the function name.
"""returns a function object given the function name.

Args:
function_name (str): The name of the function.
Expand All @@ -163,7 +163,7 @@ def get_function(self, function_name: str, file_name: Optional[str]) -> CFunctio
raise NotImplementedError("Support for this functionality has not been implemented yet.")

def get_C_file(self, file_name: str) -> str:
"""Returns a class given qualified class name.
"""returns a class given qualified class name.

Args:
file_name (str): The name of the file.
Expand Down Expand Up @@ -191,7 +191,7 @@ def get_C_compilation_unit(self, file_path: str) -> CTranslationUnit:
return self.c_application.translation_units.get(file_path)

def get_functions_in_file(self, file_name: str) -> List[CFunction]:
"""Returns a dictionary of all methods of the given class.
"""returns a dictionary of all methods of the given class.

Args:
file_name (str): The name of the file.
Expand All @@ -205,7 +205,7 @@ def get_functions_in_file(self, file_name: str) -> List[CFunction]:
raise NotImplementedError("Support for this functionality has not been implemented yet.")

def get_macros(self) -> List[CMacro]:
"""Returns a list of all macros in the C code.
"""returns a list of all macros in the C code.

Raises:
NotImplementedError: Raised when current AnalysisEngine does not support this function.
Expand All @@ -216,7 +216,7 @@ def get_macros(self) -> List[CMacro]:
raise NotImplementedError("Support for this functionality has not been implemented yet.")

def get_macros_in_file(self, file_name: str) -> List[CMacro] | None:
"""Returns a list of all macros in the given file.
"""returns a list of all macros in the given file.

Args:
file_name (str): The name of the file.
Expand All @@ -231,7 +231,7 @@ def get_macros_in_file(self, file_name: str) -> List[CMacro] | None:


def get_includes(self) -> List[str]:
"""Returns a list of all include statements across all files in the C code.
"""returns a list of all include statements across all files in the C code.

Returns:
List[str]: A list of all include statements. Returns empty list if none found.
Expand All @@ -243,7 +243,7 @@ def get_includes(self) -> List[str]:


def get_includes_in_file(self, file_name: str) -> List[str] | None:
"""Returns a list of all include statements in the given file.
"""returns a list of all include statements in the given file.

Args:
file_name (str): The name of the file to search in.
Expand All @@ -257,7 +257,7 @@ def get_includes_in_file(self, file_name: str) -> List[str] | None:


def get_macros(self) -> List[CMacro]:
"""Returns a list of all macro definitions across all files in the C code.
"""returns a list of all macro definitions across all files in the C code.

Returns:
List[CMacro]: A list of all macro definitions. Returns empty list if none found.
Expand All @@ -269,7 +269,7 @@ def get_macros(self) -> List[CMacro]:


def get_macros_in_file(self, file_name: str) -> List[CMacro] | None:
"""Returns a list of all macro definitions in the given file.
"""returns a list of all macro definitions in the given file.

Args:
file_name (str): The name of the file to search in.
Expand All @@ -283,7 +283,7 @@ def get_macros_in_file(self, file_name: str) -> List[CMacro] | None:


def get_typedefs(self) -> List[CTypedef]:
"""Returns a list of all typedef declarations across all files in the C code.
"""returns a list of all typedef declarations across all files in the C code.

Returns:
List[CTypedef]: A list of all typedef declarations. Returns empty list if none found.
Expand All @@ -295,7 +295,7 @@ def get_typedefs(self) -> List[CTypedef]:


def get_typedefs_in_file(self, file_name: str) -> List[CTypedef] | None:
"""Returns a list of all typedef declarations in the given file.
"""returns a list of all typedef declarations in the given file.

Args:
file_name (str): The name of the file to search in.
Expand All @@ -309,7 +309,7 @@ def get_typedefs_in_file(self, file_name: str) -> List[CTypedef] | None:


def get_structs(self) -> List[CStruct]:
"""Returns a list of all struct/union declarations across all files in the C code.
"""returns a list of all struct/union declarations across all files in the C code.

Returns:
List[CStruct]: A list of all struct/union declarations. Returns empty list if none found.
Expand All @@ -321,7 +321,7 @@ def get_structs(self) -> List[CStruct]:


def get_structs_in_file(self, file_name: str) -> List[CStruct] | None:
"""Returns a list of all struct/union declarations in the given file.
"""returns a list of all struct/union declarations in the given file.

Args:
file_name (str): The name of the file to search in.
Expand All @@ -335,7 +335,7 @@ def get_structs_in_file(self, file_name: str) -> List[CStruct] | None:


def get_enums(self) -> List[CEnum]:
"""Returns a list of all enum declarations across all files in the C code.
"""returns a list of all enum declarations across all files in the C code.

Returns:
List[CEnum]: A list of all enum declarations. Returns empty list if none found.
Expand All @@ -347,7 +347,7 @@ def get_enums(self) -> List[CEnum]:


def get_enums_in_file(self, file_name: str) -> List[CEnum] | None:
"""Returns a list of all enum declarations in the given file.
"""returns a list of all enum declarations in the given file.

Args:
file_name (str): The name of the file to search in.
Expand All @@ -361,7 +361,7 @@ def get_enums_in_file(self, file_name: str) -> List[CEnum] | None:


def get_globals(self, file_name: str) -> List[CVariable] | None:
"""Returns a list of all global variable declarations in the given file.
"""returns a list of all global variable declarations in the given file.

Args:
file_name (str): The name of the file to search in.
Expand Down
Loading