mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-03 12:20:38 +08:00
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
|
|
# Generated by CodiumAI
|
|
from pr_agent.algo.utils import try_fix_yaml
|
|
|
|
|
|
import pytest
|
|
|
|
class TestTryFixYaml:
|
|
|
|
# The function successfully parses a valid YAML string.
|
|
def test_valid_yaml(self):
|
|
review_text = "key: value\n"
|
|
expected_output = {"key": "value"}
|
|
assert try_fix_yaml(review_text) == expected_output
|
|
|
|
# The function adds '|-' to 'relevant line:' if it is not already present and successfully parses the YAML string.
|
|
def test_add_relevant_line(self):
|
|
review_text = "relevant line: value: 3\n"
|
|
expected_output = {"relevant line": "value: 3"}
|
|
assert try_fix_yaml(review_text) == expected_output
|
|
|
|
# The function extracts YAML snippet
|
|
def test_extract_snippet(self):
|
|
review_text = '''\
|
|
Here is the answer in YAML format:
|
|
|
|
```yaml
|
|
name: John Smith
|
|
age: 35
|
|
```
|
|
'''
|
|
expected_output = {'name': 'John Smith', 'age': 35}
|
|
assert try_fix_yaml(review_text) == expected_output
|
|
|
|
# The function removes the last line(s) of the YAML string and successfully parses the YAML string.
|
|
def test_remove_last_line(self):
|
|
review_text = "key: value\nextra invalid line\n"
|
|
expected_output = {"key": "value"}
|
|
assert try_fix_yaml(review_text) == expected_output
|
|
|
|
# The YAML string is empty.
|
|
def test_empty_yaml_fixed(self):
|
|
review_text = ""
|
|
assert try_fix_yaml(review_text) is None
|