Skip to content

Commit

Permalink
CodeTF: change descriptions are optional but must not be empty (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella authored Sep 5, 2024
1 parent 165b285 commit 51344e5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/codemodder/codemods/xml_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def add_change(self, line):
self.changes.append(
Change(
lineNumber=line,
description=self.change_description,
description=self.change_description or None,
findings=self.file_context.get_findings_for_location(line),
)
)
Expand Down
6 changes: 6 additions & 0 deletions src/codemodder/codetf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def validate_lineNumber(self):
raise ValueError("lineNumber must be greater than 0")
return self

@model_validator(mode="after")
def validate_description(self):
if self.description is not None and not self.description:
raise ValueError("description must not be empty")
return self


class AIMetadata(BaseModel):
provider: Optional[str] = None
Expand Down
9 changes: 9 additions & 0 deletions tests/test_codetf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ def test_change_invalid_line_number():
Change(lineNumber=0, description="Change 1 to 2")


def test_change_empty_description():
with pytest.raises(ValueError):
Change(lineNumber=1, description="")


def test_change_description_optional():
Change(lineNumber=1, description=None)


def test_write_codetf(tmpdir, mocker, codetf_schema):
path = tmpdir / "test.codetf.json"

Expand Down

0 comments on commit 51344e5

Please sign in to comment.