diff --git a/tests/unittest/test_convert_to_markdown.py b/tests/unittest/test_convert_to_markdown.py index 483787aa..da9e95f2 100644 --- a/tests/unittest/test_convert_to_markdown.py +++ b/tests/unittest/test_convert_to_markdown.py @@ -1,4 +1,7 @@ # Generated by CodiumAI +import textwrap +from unittest.mock import Mock + from pr_agent.algo.utils import PRReviewHeader, convert_to_markdown_v2 from pr_agent.tools.pr_description import insert_br_after_x_chars @@ -48,9 +51,143 @@ class TestConvertToMarkdown: input_data = {'review': { 'estimated_effort_to_review_[1-5]': '1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n', 'relevant_tests': 'No\n', 'possible_issues': 'No\n', 'security_concerns': 'No\n'}} + + expected_output = textwrap.dedent(f"""\ + {PRReviewHeader.REGULAR.value} ๐Ÿ” + + Here are some key observations to aid the review process: + + + + + + +
โฑ๏ธ Estimated effort to review: 1 ๐Ÿ”ตโšชโšชโšชโšช
๐Ÿงช No relevant tests
 Possible issues: No +
๐Ÿ”’ No security concerns identified
+ """) + + assert convert_to_markdown_v2(input_data).strip() == expected_output.strip() + + def test_simple_dictionary_input_without_gfm_supported(self): + input_data = {'review': { + 'estimated_effort_to_review_[1-5]': '1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n', + 'relevant_tests': 'No\n', 'possible_issues': 'No\n', 'security_concerns': 'No\n'}} + + expected_output = textwrap.dedent("""\ + ## PR Reviewer Guide ๐Ÿ” + + Here are some key observations to aid the review process: + + ### โฑ๏ธ Estimated effort to review: 1 ๐Ÿ”ตโšชโšชโšชโšช + + ### ๐Ÿงช No relevant tests + + ### Possible issues: No - expected_output = f'{PRReviewHeader.REGULAR.value} ๐Ÿ”\n\nHere are some key observations to aid the review process:\n\n\n\n\n\n\n
โฑ๏ธ Estimated effort to review: 1 ๐Ÿ”ตโšชโšชโšชโšช
๐Ÿงช No relevant tests
 Possible issues: No\n
๐Ÿ”’ No security concerns identified
' + ### ๐Ÿ”’ No security concerns identified + """) + + assert convert_to_markdown_v2(input_data, gfm_supported=False).strip() == expected_output.strip() + + def test_key_issues_to_review(self): + input_data = {'review': { + 'key_issues_to_review': [ + { + 'relevant_file' : 'src/utils.py', + 'issue_header' : 'Code Smell', + 'issue_content' : 'The function is too long and complex.', + 'start_line': 30, + 'end_line': 50, + } + ] + }} + mock_git_provider = Mock() + reference_link = 'https://github.com/qodo/pr-agent/pull/1/files#diff-hashvalue-R174' + mock_git_provider.get_line_link.return_value = reference_link + + expected_output = textwrap.dedent(f"""\ + ## PR Reviewer Guide ๐Ÿ” + + Here are some key observations to aid the review process: + + + +
โšก Recommended focus areas for review

+ + Code Smell
The function is too long and complex. + +
+ """) + + assert convert_to_markdown_v2(input_data, git_provider=mock_git_provider).strip() == expected_output.strip() + mock_git_provider.get_line_link.assert_called_with('src/utils.py', 30, 50) + + def test_ticket_compliance(self): + input_data = {'review': { + 'ticket_compliance_check': [ + { + 'ticket_url': 'https://example.com/ticket/123', + 'ticket_requirements': '- Requirement 1\n- Requirement 2\n', + 'fully_compliant_requirements': '- Requirement 1\n- Requirement 2\n', + 'not_compliant_requirements': '', + 'requires_further_human_verification': '', + } + ] + }} + + expected_output = textwrap.dedent("""\ + ## PR Reviewer Guide ๐Ÿ” + + Here are some key observations to aid the review process: + + + +
+ + **๐ŸŽซ Ticket compliance analysis โœ…** + + + + **[123](https://example.com/ticket/123) - Fully compliant** + + Compliant requirements: + + - Requirement 1 + - Requirement 2 + + + +
+ """) + + assert convert_to_markdown_v2(input_data).strip() == expected_output.strip() + + def test_can_be_split(self): + input_data = {'review': { + 'can_be_split': [ + { + 'relevant_files': [ + 'src/file1.py', + 'src/file2.py' + ], + 'title': 'Split PR into smaller parts', + } + ] + } + } + + expected_output = textwrap.dedent("""\ + ## PR Reviewer Guide ๐Ÿ” + + Here are some key observations to aid the review process: + + + +
๐Ÿ”€ No multiple PR themes + +
+ """) assert convert_to_markdown_v2(input_data).strip() == expected_output.strip()