mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 04:40:38 +08:00
Add tests
This commit is contained in:
91
tests/unit/test_fix_output.py
Normal file
91
tests/unit/test_fix_output.py
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
# Generated by CodiumAI
|
||||||
|
from pr_agent.algo.utils import try_fix_json
|
||||||
|
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
class TestTryFixJson:
|
||||||
|
# Tests that JSON with complete 'Code suggestions' section returns expected output
|
||||||
|
def test_incomplete_code_suggestions(self):
|
||||||
|
review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"suggestion number": 1, "relevant file": "xxx.py", "suggestion content": "xxx [important]"}, {"suggestion number": 2, "relevant file": "yyy.py", "suggestion content": "yyy [incomp...'
|
||||||
|
expected_output = {
|
||||||
|
'PR Analysis': {
|
||||||
|
'Main theme': 'xxx',
|
||||||
|
'Description and title': 'Yes',
|
||||||
|
'Type of PR': 'Bug fix'
|
||||||
|
},
|
||||||
|
'PR Feedback': {
|
||||||
|
'General PR suggestions': '..., `xxx`...',
|
||||||
|
'Code suggestions': [
|
||||||
|
{
|
||||||
|
'suggestion number': 1,
|
||||||
|
'relevant file': 'xxx.py',
|
||||||
|
'suggestion content': 'xxx [important]'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert try_fix_json(review) == expected_output
|
||||||
|
|
||||||
|
def test_incomplete_code_suggestions_new_line(self):
|
||||||
|
review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"suggestion number": 1, "relevant file": "xxx.py", "suggestion content": "xxx [important]"} \n\t, {"suggestion number": 2, "relevant file": "yyy.py", "suggestion content": "yyy [incomp...'
|
||||||
|
expected_output = {
|
||||||
|
'PR Analysis': {
|
||||||
|
'Main theme': 'xxx',
|
||||||
|
'Description and title': 'Yes',
|
||||||
|
'Type of PR': 'Bug fix'
|
||||||
|
},
|
||||||
|
'PR Feedback': {
|
||||||
|
'General PR suggestions': '..., `xxx`...',
|
||||||
|
'Code suggestions': [
|
||||||
|
{
|
||||||
|
'suggestion number': 1,
|
||||||
|
'relevant file': 'xxx.py',
|
||||||
|
'suggestion content': 'xxx [important]'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert try_fix_json(review) == expected_output
|
||||||
|
|
||||||
|
def test_incomplete_code_suggestions_many_close_brackets(self):
|
||||||
|
review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"suggestion number": 1, "relevant file": "xxx.py", "suggestion content": "xxx [important]"} \n, {"suggestion number": 2, "relevant file": "yyy.py", "suggestion content": "yyy }, [}\n ,incomp.} ,..'
|
||||||
|
expected_output = {
|
||||||
|
'PR Analysis': {
|
||||||
|
'Main theme': 'xxx',
|
||||||
|
'Description and title': 'Yes',
|
||||||
|
'Type of PR': 'Bug fix'
|
||||||
|
},
|
||||||
|
'PR Feedback': {
|
||||||
|
'General PR suggestions': '..., `xxx`...',
|
||||||
|
'Code suggestions': [
|
||||||
|
{
|
||||||
|
'suggestion number': 1,
|
||||||
|
'relevant file': 'xxx.py',
|
||||||
|
'suggestion content': 'xxx [important]'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert try_fix_json(review) == expected_output
|
||||||
|
|
||||||
|
def test_incomplete_code_suggestions_relevant_file(self):
|
||||||
|
review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"suggestion number": 1, "relevant file": "xxx.py", "suggestion content": "xxx [important]"}, {"suggestion number": 2, "relevant file": "yyy.p'
|
||||||
|
expected_output = {
|
||||||
|
'PR Analysis': {
|
||||||
|
'Main theme': 'xxx',
|
||||||
|
'Description and title': 'Yes',
|
||||||
|
'Type of PR': 'Bug fix'
|
||||||
|
},
|
||||||
|
'PR Feedback': {
|
||||||
|
'General PR suggestions': '..., `xxx`...',
|
||||||
|
'Code suggestions': [
|
||||||
|
{
|
||||||
|
'suggestion number': 1,
|
||||||
|
'relevant file': 'xxx.py',
|
||||||
|
'suggestion content': 'xxx [important]'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert try_fix_json(review) == expected_output
|
Reference in New Issue
Block a user