Skip to content
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
8 changes: 3 additions & 5 deletions src/codemodder/codetf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Optional

from pydantic import BaseModel, model_validator
from pydantic import BaseModel, ConfigDict, model_validator

from codemodder import __version__
from codemodder.logging import logger
Expand Down Expand Up @@ -138,16 +138,14 @@ class Rule(BaseModel):
name: str
url: Optional[str] = None

class Config:
frozen = True
model_config = ConfigDict(frozen=True)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix deprecation warning



class Finding(BaseModel):
id: Optional[str] = None
rule: Rule

class Config:
frozen = True
model_config = ConfigDict(frozen=True)

def to_unfixed_finding(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def from_json(cls, json_file: str | Path) -> Self:
data = json.load(file)

result_set = cls()
for result in data.get("issues") or [] + data.get("hotspots") or []:
for result in data.get("issues", []) + data.get("hotspots", []):
if result["status"].lower() in ("open", "to_review"):
result_set.add_result(SonarResult.from_result(result))

Expand Down
36 changes: 35 additions & 1 deletion tests/test_sonar_results.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from core_codemods.sonar.results import SonarResult
from pathlib import Path

from core_codemods.sonar.results import SonarResult, SonarResultSet

SAMPLE_DIR = Path(__file__).parent / "samples"


def test_result_without_textrange():
Expand Down Expand Up @@ -29,3 +33,33 @@ def test_result_without_textrange():
assert sonar_result.finding_id == "AZJnP4pZPJb5bI8DP25Y"
assert sonar_result.locations == ()
assert sonar_result.codeflows == ()


def test_parse_issues_json():
results = SonarResultSet.from_json(SAMPLE_DIR / "sonar_issues.json")
assert len(results) == 34


def test_parse_hotspots_json():
results = SonarResultSet.from_json(SAMPLE_DIR / "sonar_hotspots.json")
assert len(results) == 2


def test_empty_issues(tmpdir, caplog):
empty_json = tmpdir / "empty.json"
empty_json.write_text('{"issues": []}', encoding="utf-8")

results = SonarResultSet.from_json(empty_json)

assert len(results) == 0
assert "Could not parse sonar json" not in caplog.text


def test_empty_hotspots(tmpdir, caplog):
empty_json = tmpdir / "empty.json"
empty_json.write_text('{"hotspots": []}', encoding="utf-8")

results = SonarResultSet.from_json(empty_json)

assert len(results) == 0
assert "Could not parse sonar json" not in caplog.text
Loading