remove suggestion number

This commit is contained in:
mrT23
2023-07-13 08:10:36 +03:00
parent 25bc69f70e
commit 4b8420aa16
5 changed files with 5 additions and 29 deletions

View File

@ -53,10 +53,7 @@ def parse_code_suggestion(code_suggestions: dict) -> str:
code_str_indented = textwrap.indent(code_str, ' ')
markdown_text += f" - **{code_key}:**\n{code_str_indented}\n"
else:
if "suggestion number" in sub_key.lower():
# markdown_text += f"- **suggestion {sub_value}:**\n" # prettier formatting
pass
elif "relevant file" in sub_key.lower():
if "relevant file" in sub_key.lower():
markdown_text += f"\n - **{sub_key}:** {sub_value}\n"
else:
markdown_text += f" **{sub_key}:** {sub_value}\n"

View File

@ -47,10 +47,6 @@ You must use the following JSON schema to format your answer:
"maxItems": {{ num_code_suggestions }},
"uniqueItems": true,
"items": {
"suggestion number": {
"type": "int",
"description": "suggestion number, starting from 1"
},
"relevant file": {
"type": "string",
"description": "the relevant file name"
@ -115,7 +111,6 @@ Example output:
"General PR suggestions": "..., `xxx`...",
"Code suggestions": [
{
"suggestion number": 1,
"relevant file": "xxx.py",
"suggestion content": "xxx [important]",
{%- if extended_code_suggestions %}

View File

@ -54,14 +54,12 @@ class TestConvertToMarkdown:
'General PR suggestions': 'general suggestion...',
'Code suggestions': [
{
'Suggestion number': 1,
'Code example': {
'Before': 'Code before',
'After': 'Code after'
}
},
{
'Suggestion number': 2,
'Code example': {
'Before': 'Code before 2',
'After': 'Code after 2'

View File

@ -7,7 +7,7 @@ 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...'
review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"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',
@ -18,7 +18,6 @@ class TestTryFixJson:
'General PR suggestions': '..., `xxx`...',
'Code suggestions': [
{
'suggestion number': 1,
'relevant file': 'xxx.py',
'suggestion content': 'xxx [important]'
}
@ -28,7 +27,7 @@ class TestTryFixJson:
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...'
review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"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',
@ -39,7 +38,6 @@ class TestTryFixJson:
'General PR suggestions': '..., `xxx`...',
'Code suggestions': [
{
'suggestion number': 1,
'relevant file': 'xxx.py',
'suggestion content': 'xxx [important]'
}
@ -49,7 +47,7 @@ class TestTryFixJson:
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.} ,..'
review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"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',
@ -60,7 +58,6 @@ class TestTryFixJson:
'General PR suggestions': '..., `xxx`...',
'Code suggestions': [
{
'suggestion number': 1,
'relevant file': 'xxx.py',
'suggestion content': 'xxx [important]'
}
@ -70,7 +67,7 @@ class TestTryFixJson:
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'
review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"relevant file": "xxx.py", "suggestion content": "xxx [important]"}, {"suggestion number": 2, "relevant file": "yyy.p'
expected_output = {
'PR Analysis': {
'Main theme': 'xxx',
@ -81,7 +78,6 @@ class TestTryFixJson:
'General PR suggestions': '..., `xxx`...',
'Code suggestions': [
{
'suggestion number': 1,
'relevant file': 'xxx.py',
'suggestion content': 'xxx [important]'
}

View File

@ -41,14 +41,6 @@ class TestParseCodeSuggestion:
expected_output = "\n" # modified to expect a newline character
assert parse_code_suggestion(input_data) == expected_output
# Tests that function returns correct output when 'suggestion number' key has a non-integer value
def test_non_integer_suggestion_number(self):
input_data = {
"Suggestion number": "one",
"Description": "This is a suggestion"
}
expected_output = " **Description:** This is a suggestion\n\n"
assert parse_code_suggestion(input_data) == expected_output
# Tests that function returns correct output when 'before' or 'after' key has a non-string value
def test_non_string_before_or_after(self):
@ -64,7 +56,6 @@ class TestParseCodeSuggestion:
# Tests that function returns correct output when input dictionary does not have 'code example' key
def test_no_code_example_key(self):
code_suggestions = {
'suggestion number': 1,
'suggestion': 'Suggestion 1',
'description': 'Description 1',
'before': 'Before 1',
@ -76,7 +67,6 @@ class TestParseCodeSuggestion:
# Tests that function returns correct output when input dictionary has 'code example' key
def test_with_code_example_key(self):
code_suggestions = {
'suggestion number': 2,
'suggestion': 'Suggestion 2',
'description': 'Description 2',
'code example': {