Skip to content

Commit bec7ad7

Browse files
authored
Merge pull request #62 from IBM/fix-testcases
Testcase fix up at 58%
2 parents b5c663b + 4de3644 commit bec7ad7

File tree

14 files changed

+445
-17
lines changed

14 files changed

+445
-17
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# Log file
66
*.log
77

8+
# Code coverage files
9+
.coverage
10+
811
# Gradle files
912
.gradle
1013

Makefile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Makefile targets for dvelopment an testing
2+
# Use make help for more info
3+
4+
.PHONY: help
5+
help: ## Display this help.
6+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
7+
8+
.PHONY: all
9+
all: help
10+
11+
##@ Development
12+
13+
.PHONY: venv
14+
venv: ## Create a Python virtual environment
15+
$(info Creating Python 3 virtual environment...)
16+
poetry shell
17+
18+
.PHONY: install
19+
install: ## Install Python dependencies in virtual environment
20+
$(info Installing dependencies...)
21+
poetry config virtualenvs.in-project true
22+
poetry install
23+
24+
.PHONY: lint
25+
lint: ## Run the linter
26+
$(info Running linting...)
27+
flake8 cldk --count --select=E9,F63,F7,F82 --show-source --statistics
28+
flake8 cldk --count --max-complexity=10 --max-line-length=180 --statistics
29+
pylint cldk --max-line-length=180
30+
31+
.PHONY: test
32+
test: ## Run the unit tests
33+
$(info Running tests...)
34+
pytest --pspec --cov=cldk --cov-fail-under=50 --disable-warnings
35+
36+
##@ Build
37+
38+
.PHONY: clean
39+
clean: ## Cleans up from previous compiles
40+
$(info Cleaning up compile artifacts...)
41+
rm -fr dist
42+
43+
.PHONY: refresh
44+
refresh: ## Refresh code analyzer
45+
$(info Refreshing CodeAnalyzer...)
46+
wget $(curl -s https://api.github.com/repos/IBM/codenet-minerva-code-analyzer/releases/latest | grep "browser_download_url" | grep codeanalyzer.jar | cut -d '"' -f 4)
47+
mv codeanalyzer.jar cldk/analysis/java/codeanalyzer/jar/codeanalyzer.jar
48+
49+
.PHONY: build
50+
build: ## Builds a new Python wheel
51+
$(info Building artifacts...)
52+
poetry build

cldk/analysis/javascript/treesitter/javascript_sitter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def __get_top_level_functions(self, code: str) -> List[JsCallable]:
184184

185185
query = """
186186
(program [
187-
(function_declaration) @function
187+
(function_declaration) @function
188188
(export_statement (function_declaration) @function.export)
189189
])
190190
"""
@@ -210,7 +210,7 @@ def __get_top_level_generators(self, code: str) -> List[JsCallable]:
210210

211211
query = """
212212
(program [
213-
(generator_function_declaration) @generator
213+
(generator_function_declaration) @generator
214214
(export_statement (generator_function_declaration) @generator.export)
215215
])
216216
"""

cldk/models/java/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828

2929
from .constants_namespace import ConstantsNamespace
3030

31-
__all__ = [JApplication, JCallable, JType, JCompilationUnit, JGraphEdges, ConstantsNamespace]
31+
__all__ = ["JApplication", "JCallable", "JType", "JCompilationUnit", "JGraphEdges", "ConstantsNamespace"]

cldk/models/java/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ class JCallable(BaseModel):
183183
cyclomatic_complexity: int | None
184184

185185
def __hash__(self):
186+
"""
187+
Returns the hash value of the declaration.
188+
"""
186189
return hash(self.declaration)
187190

188191
@model_validator(mode="after")

cldk/models/javascript/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@
1717
"""
1818
JavaScript package
1919
"""
20+
21+
from .models import JsParameter, JsCallable, JsClass, JsProgram
22+
23+
__all__ = ["JsParameter", "JsCallable", "JsClass", "JsProgram"]

cldk/models/javascript/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class JsParameter(BaseModel):
3939
name: str
4040
default_value: Optional[str] = None
4141
is_rest: bool = False
42-
# type: Optional[str] - might be able to extract from JsDoc
42+
# type Optional[str] - might be able to extract from JsDoc
4343

4444

4545
class JsCallable(BaseModel):

cldk/models/treesitter/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Capture:
4848
name: str
4949

5050
def __init__(self, captures: Dict[str, List[Node]]):
51+
self.captures = []
5152
for capture_name, captures in captures.items():
5253
self.captures = [self.Capture(node=node, name=capture_name) for node in captures]
5354

poetry.lock

Lines changed: 298 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ tree-sitter-javascript = "0.23.0"
4848
[tool.poetry.group.dev.dependencies]
4949
toml = "^0.10.2"
5050
pytest = "8.3.3"
51+
pytest-pspec = "^0.0.4"
52+
pytest-cov = "^5.0.0"
53+
pylint = "^3.2.2"
54+
flake8 = "^7.0.0"
55+
black = "^24.4.2"
56+
coverage = "^7.5.3"
5157
jupyter = "^1.0.0"
5258

5359
# Documentation
@@ -58,9 +64,53 @@ mkdocstrings = "0.26.1"
5864
requires = ["poetry-core"]
5965
build-backend = "poetry.core.masonry.api"
6066

67+
########################################
68+
# Tool configurations
69+
########################################
70+
[tool.flake8]
71+
max-line-length = 180
72+
count = true
73+
6174
[tool.black]
6275
line-length = 180
6376

77+
[tool.pylint.'MESSAGES CONTROL']
78+
disable = "no-member,protected-access,global-statement"
79+
80+
[tool.pylint.FORMAT]
81+
max-line-length = 180
82+
83+
[tool.pytest.ini_options]
84+
minversion = "6.0"
85+
addopts = "--pspec --cov=cldk --cov-fail-under=50"
86+
testpaths = ["tests"]
87+
88+
[tool.coverage.run]
89+
source = ["cldk"]
90+
omit = [
91+
"venv/*",
92+
".venv/*"
93+
]
94+
95+
[tool.coverage.report]
96+
show_missing = true
97+
exclude_lines = [
98+
"pragma: no cover",
99+
"pragma: no branch",
100+
"pass",
101+
"subprocess.CalledProcessError",
102+
"sys.exit",
103+
"if __name__ == .__main__.:"
104+
]
105+
ignore_errors = true
106+
107+
[tool.coverage.xml]
108+
output="./coverage.xml"
109+
110+
[tool.coverage.html]
111+
title = "Test Coverage Report"
112+
directory = "coverage_html_report"
113+
64114
[tool.cldk.testing]
65115
sample-application = "tests/resources/java/application/"
66116
sample-application-analysis-json = "tests/resources/java/analysis_json/"

0 commit comments

Comments
 (0)