From 9384f2d5e58a190956a5d8dde92a10fbbc97a59c Mon Sep 17 00:00:00 2001 From: Saurav Panda Date: Sat, 6 Apr 2024 10:58:05 -0400 Subject: [PATCH] fix: Added test for review case --- tests/actions/test_review.py | 21 +++++++++++++++++++++ tests/data/actions/valid_review.json | 7 +++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/actions/test_review.py create mode 100644 tests/data/actions/valid_review.json diff --git a/tests/actions/test_review.py b/tests/actions/test_review.py new file mode 100644 index 00000000..911acaa5 --- /dev/null +++ b/tests/actions/test_review.py @@ -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 diff --git a/tests/data/actions/valid_review.json b/tests/data/actions/valid_review.json new file mode 100644 index 00000000..e0be08a2 --- /dev/null +++ b/tests/data/actions/valid_review.json @@ -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
\nThe code is well-structured and easy to read.\n\n### Reason\nThe code follows best practices and coding standards.\n\n### Confidence\nHigh\n
\n\n### Performance\n\n\n
\nThe code could be optimized for better performance.\n\n### Reason\nThere are some inefficient loops and data structures used.\n\n### Confidence\nMedium\n
\n\n### Security\n\n\n
\nNA\n\n### Reason\nNA\n\n### Confidence\nNA\n
\n" + } +] \ No newline at end of file