Skip to content

Commit

Permalink
fix: Added test for review case
Browse files Browse the repository at this point in the history
  • Loading branch information
sauravpanda committed Apr 6, 2024
1 parent a9144e7 commit 9384f2d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/actions/test_review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest
from unittest.mock import patch, Mock
import json
from cloudcode.actions.reviews import CodeReviewer
from fuzzywuzzy import fuzz

with open("tests/data/actions/valid_review.json") as f:
data = json.load(f)


@pytest.mark.parametrize("valid_review", data)
def test_review_pull_request(valid_review):
# Act
code_reviewer = CodeReviewer()
result = code_reviewer.review_pull_request(
valid_review["input"]["diff"],
valid_review["input"]["title"],
valid_review["input"]["description"],
)

assert fuzz.ratio(result, valid_review["output"]) > 95
7 changes: 7 additions & 0 deletions tests/data/actions/valid_review.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"input": {"diff": "", "title": "Test Title", "description": "Test description"},
"llm_resp": "{\"review\": [{\"topic\": \"Code Quality\", \"comment\": \"The code is well-structured and easy to read.\", \"reasoning\": \"The code follows best practices and coding standards.\", \"confidence\": \"High\"}, {\"topic\": \"Performance\", \"comment\": \"The code could be optimized for better performance.\", \"reasoning\": \"There are some inefficient loops and data structures used.\", \"confidence\": \"Medium\"}, {\"topic\": \"Security\", \"comment\": \"NA\", \"reasoning\": \"NA\", \"confidence\": \"NA\"}]}",
"output": "\n## Code Review Feedback\n\n### Code Quality\n\n\n<details>\n<summary>The code is well-structured and easy to read.</summary>\n\n### Reason\nThe code follows best practices and coding standards.\n\n### Confidence\nHigh\n</details>\n\n### Performance\n\n\n<details>\n<summary>The code could be optimized for better performance.</summary>\n\n### Reason\nThere are some inefficient loops and data structures used.\n\n### Confidence\nMedium\n</details>\n\n### Security\n\n\n<details>\n<summary>NA</summary>\n\n### Reason\nNA\n\n### Confidence\nNA\n</details>\n"
}
]

0 comments on commit 9384f2d

Please sign in to comment.