2023-08-09 08:50:15 +03:00
# Generated by CodiumAI
import pytest
2023-11-20 10:35:35 +02:00
import yaml
from yaml . scanner import ScannerError
2023-08-09 08:50:15 +03:00
from pr_agent . algo . utils import load_yaml
class TestLoadYaml :
# Tests that load_yaml loads a valid YAML string
def test_load_valid_yaml ( self ) :
yaml_str = ' name: John Smith \n age: 35 '
expected_output = { ' name ' : ' John Smith ' , ' age ' : 35 }
assert load_yaml ( yaml_str ) == expected_output
2023-12-20 11:13:14 +09:00
def test_load_valid_yaml_with_description ( self ) :
yaml_str = ''' \
Here is the answer in YAML format :
` ` ` yaml
name : John Smith
age : 35
` ` `
'''
expected_output = { ' name ' : ' John Smith ' , ' age ' : 35 }
assert load_yaml ( yaml_str ) == expected_output
2023-11-19 17:30:57 +02:00
def test_load_invalid_yaml1 ( self ) :
2023-08-09 08:50:15 +03:00
yaml_str = \
''' \
PR Analysis :
Main theme : Enhancing the ` / describe ` command prompt by adding title and description
Type of PR : Enhancement
Relevant tests added : No
Focused PR : Yes , the PR is focused on enhancing the ` / describe ` command prompt .
PR Feedback :
General suggestions : The PR seems to be well - structured and focused on a specific enhancement . However , it would be beneficial to add tests to ensure the new feature works as expected .
Code feedback :
- relevant file : pr_agent / settings / pr_description_prompts . toml
suggestion : Consider using a more descriptive variable name than ' user ' for the command prompt . A more descriptive name would make the code more readable and maintainable . [ medium ]
2023-11-20 10:30:59 +02:00
relevant line : user = """ PR Info: aaa
2023-08-09 08:50:15 +03:00
Security concerns : No '''
2023-11-20 10:35:35 +02:00
with pytest . raises ( ScannerError ) :
yaml . safe_load ( yaml_str )
2023-11-20 10:30:59 +02:00
expected_output = { ' PR Analysis ' : { ' Main theme ' : ' Enhancing the `/describe` command prompt by adding title and description ' , ' Type of PR ' : ' Enhancement ' , ' Relevant tests added ' : False , ' Focused PR ' : ' Yes, the PR is focused on enhancing the `/describe` command prompt. ' } , ' PR Feedback ' : { ' General suggestions ' : ' The PR seems to be well-structured and focused on a specific enhancement. However, it would be beneficial to add tests to ensure the new feature works as expected. ' , ' Code feedback ' : [ { ' relevant file ' : ' pr_agent/settings/pr_description_prompts.toml ' , ' suggestion ' : " Consider using a more descriptive variable name than ' user ' for the command prompt. A more descriptive name would make the code more readable and maintainable. [medium] " , ' relevant line ' : ' user= " " " PR Info: aaa ' } ] , ' Security concerns ' : False } }
2023-08-09 08:50:15 +03:00
assert load_yaml ( yaml_str ) == expected_output
2023-11-19 17:30:57 +02:00
def test_load_invalid_yaml2 ( self ) :
yaml_str = ''' \
2023-11-20 10:30:59 +02:00
- relevant file : src / app . py :
suggestion content : The print statement is outside inside the if __name__ == : \
2023-11-19 17:30:57 +02:00
'''
2023-11-20 10:35:35 +02:00
with pytest . raises ( ScannerError ) :
yaml . safe_load ( yaml_str )
2023-11-20 10:30:59 +02:00
expected_output = [ { ' relevant file ' : ' src/app.py: ' ,
' suggestion content ' : ' The print statement is outside inside the if __name__ ==: ' } ]
2023-11-19 17:30:57 +02:00
assert load_yaml ( yaml_str ) == expected_output
2023-11-20 10:30:59 +02:00