2023-07-06 00:21:08 +03:00
# Generated by CodiumAI
from pr_agent . algo . utils import convert_to_markdown
2024-02-05 09:20:36 +02:00
from pr_agent . tools . pr_description import insert_br_after_x_chars
2023-07-11 16:55:09 +03:00
2023-07-06 00:21:08 +03:00
"""
Code Analysis
Objective :
The objective of the ' convert_to_markdown ' function is to convert a dictionary of data into a markdown - formatted text .
The function takes in a dictionary as input and recursively iterates through its keys and values to generate the
markdown text .
Inputs :
- A dictionary of data containing information about a pull request .
Flow :
- Initialize an empty string variable ' markdown_text ' .
- Create a dictionary ' emojis ' containing emojis for each key in the input dictionary .
- Iterate through the input dictionary :
- If the value is empty , continue to the next iteration .
- If the value is a dictionary , recursively call the ' convert_to_markdown ' function with the value as input and
append the returned markdown text to ' markdown_text ' .
- If the value is a list :
- If the key is ' code suggestions ' , add an additional line break to ' markdown_text ' .
- Get the corresponding emoji for the key from the ' emojis ' dictionary . If no emoji is found , use a dash .
- Append the emoji and key to ' markdown_text ' .
- Iterate through the items in the list :
- If the item is a dictionary and the key is ' code suggestions ' , call the ' parse_code_suggestion ' function with
the item as input and append the returned markdown text to ' markdown_text ' .
- If the item is not empty , append it to ' markdown_text ' .
- If the value is not ' n/a ' , get the corresponding emoji for the key from the ' emojis ' dictionary . If no emoji is
found , use a dash . Append the emoji , key , and value to ' markdown_text ' .
- Return ' markdown_text ' .
Outputs :
- A markdown - formatted string containing the information from the input dictionary .
Additional aspects :
- The function uses recursion to handle nested dictionaries .
- The ' parse_code_suggestion ' function is called for items in the ' code suggestions ' list .
- The function uses emojis to add visual cues to the markdown text .
"""
class TestConvertToMarkdown :
# Tests that the function works correctly with a simple dictionary input
def test_simple_dictionary_input ( self ) :
input_data = {
' Main theme ' : ' Test ' ,
' Type of PR ' : ' Test type ' ,
' Relevant tests added ' : ' no ' ,
2023-07-11 08:50:28 +03:00
' Focused PR ' : ' Yes ' ,
2023-07-06 00:21:08 +03:00
' General PR suggestions ' : ' general suggestion... ' ,
2023-08-06 18:20:39 +03:00
' Code feedback ' : [
2023-07-06 00:21:08 +03:00
{
' Code example ' : {
' Before ' : ' Code before ' ,
' After ' : ' Code after '
}
} ,
{
' Code example ' : {
' Before ' : ' Code before 2 ' ,
' After ' : ' Code after 2 '
}
}
]
}
expected_output = """ \
2023-08-22 20:21:52 +03:00
- 🎯 * * Main theme : * * Test \n \
- 📌 * * Type of PR : * * Test type \n \
- 🧪 * * Relevant tests added : * * no \n \
- ✨ * * Focused PR : * * Yes \n \
2023-12-26 08:26:18 +02:00
- * * General PR suggestions : * * general suggestion . . . \n \n \n < details > < summary > < strong > 🤖 Code feedback : < / strong > < / summary > - * * Code example : * * \n - * * Before : * * \n ` ` ` \n Code before \n ` ` ` \n - * * After : * * \n ` ` ` \n Code after \n ` ` ` \n \n - * * Code example : * * \n - * * Before : * * \n ` ` ` \n Code before 2 \n ` ` ` \n - * * After : * * \n ` ` ` \n Code after 2 \n ` ` ` \n \n < / details > \
2023-07-06 00:21:08 +03:00
"""
assert convert_to_markdown ( input_data ) . strip ( ) == expected_output . strip ( )
# Tests that the function works correctly with an empty dictionary input
def test_empty_dictionary_input ( self ) :
input_data = { }
expected_output = " "
assert convert_to_markdown ( input_data ) . strip ( ) == expected_output . strip ( )
def test_dictionary_input_containing_only_empty_dictionaries ( self ) :
input_data = {
' Main theme ' : { } ,
' Type of PR ' : { } ,
' Relevant tests added ' : { } ,
2023-07-11 08:50:28 +03:00
' Focused PR ' : { } ,
2023-07-06 00:21:08 +03:00
' General PR suggestions ' : { } ,
' Code suggestions ' : { }
}
2023-08-22 20:21:52 +03:00
expected_output = ' '
2023-07-06 00:21:08 +03:00
assert convert_to_markdown ( input_data ) . strip ( ) == expected_output . strip ( )
2024-02-05 09:20:36 +02:00
class TestBR :
def test_br1 ( self ) :
2024-02-05 10:12:47 +02:00
file_change_description = ' - Imported `FilePatchInfo` and `EDIT_TYPE` from `pr_agent.algo.types` instead of `pr_agent.git_providers.git_provider`. '
2024-02-05 09:20:36 +02:00
file_change_description_br = insert_br_after_x_chars ( file_change_description )
2024-02-05 10:12:47 +02:00
expected_output = ( ' <li>Imported <code>FilePatchInfo</code> and <code>EDIT_TYPE</code> from '
' <code>pr_agent.algo.types</code> instead <br>of '
' <code>pr_agent.git_providers.git_provider</code>. ' )
2024-02-05 09:20:36 +02:00
assert file_change_description_br == expected_output
# print("-----")
# print(file_change_description_br)
def test_br2 ( self ) :
file_change_description = ( ' - Created a - new -class `ColorPaletteResourcesCollection ColorPaletteResourcesCollection '
' ColorPaletteResourcesCollection ColorPaletteResourcesCollection` ' )
file_change_description_br = insert_br_after_x_chars ( file_change_description )
2024-02-05 10:12:47 +02:00
expected_output = ( ' <li>Created a - new -class <code>ColorPaletteResourcesCollection </code><br><code> '
2024-02-05 13:00:57 +02:00
' ColorPaletteResourcesCollection ColorPaletteResourcesCollection '
' </code><br><code>ColorPaletteResourcesCollection</code> ' )
2024-02-05 09:20:36 +02:00
assert file_change_description_br == expected_output
# print("-----")
2024-02-05 10:12:47 +02:00
# print(file_change_description_br)
2024-02-05 13:00:57 +02:00
def test_br3 ( self ) :
file_change_description = ' Created a new class `ColorPaletteResourcesCollection` which extends `AvaloniaDictionary<ThemeVariant, ColorPaletteResources>` and implements aaa '
file_change_description_br = insert_br_after_x_chars ( file_change_description )
assert file_change_description_br == ( ' Created a new class <code>ColorPaletteResourcesCollection</code> which '
' extends <br><code>AvaloniaDictionary<ThemeVariant, ColorPaletteResources> '
' </code> and implements <br>aaa ' )
# print("-----")
# print(file_change_description_br)