mirror of
https://github.com/hwchase17/langchain
synced 2024-10-29 17:07:25 +00:00
6df90ad9fd
adds tests cases, consolidates a lot of PRs
109 lines
1.2 KiB
Python
109 lines
1.2 KiB
Python
import pytest
|
|
|
|
from langchain.output_parsers.json import parse_json_markdown
|
|
|
|
GOOD_JSON = """```json
|
|
{
|
|
"foo": "bar"
|
|
}
|
|
```"""
|
|
|
|
JSON_WITH_NEW_LINES = """
|
|
|
|
```json
|
|
{
|
|
"foo": "bar"
|
|
}
|
|
```
|
|
|
|
"""
|
|
|
|
JSON_WITH_NEW_LINES_INSIDE = """```json
|
|
{
|
|
|
|
"foo": "bar"
|
|
|
|
}
|
|
```"""
|
|
|
|
JSON_WITH_NEW_LINES_EVERYWHERE = """
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"foo": "bar"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
"""
|
|
|
|
TICKS_WITH_NEW_LINES_EVERYWHERE = """
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"foo": "bar"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
"""
|
|
|
|
NO_TICKS = """{
|
|
"foo": "bar"
|
|
}"""
|
|
|
|
NO_TICKS_WHITE_SPACE = """
|
|
{
|
|
"foo": "bar"
|
|
}
|
|
"""
|
|
|
|
TEXT_BEFORE = """Thought: I need to use the search tool
|
|
|
|
Action:
|
|
```
|
|
{
|
|
"foo": "bar"
|
|
}
|
|
```"""
|
|
|
|
TEXT_AFTER = """```
|
|
{
|
|
"foo": "bar"
|
|
}
|
|
```
|
|
This should do the trick"""
|
|
|
|
TEXT_BEFORE_AND_AFTER = """Action: Testing
|
|
|
|
```
|
|
{
|
|
"foo": "bar"
|
|
}
|
|
```
|
|
This should do the trick"""
|
|
|
|
TEST_CASES = [
|
|
GOOD_JSON,
|
|
JSON_WITH_NEW_LINES,
|
|
JSON_WITH_NEW_LINES_INSIDE,
|
|
JSON_WITH_NEW_LINES_EVERYWHERE,
|
|
TICKS_WITH_NEW_LINES_EVERYWHERE,
|
|
NO_TICKS,
|
|
NO_TICKS_WHITE_SPACE,
|
|
TEXT_BEFORE,
|
|
TEXT_AFTER,
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("json_string", TEST_CASES)
|
|
def test_parse_json(json_string: str) -> None:
|
|
parsed = parse_json_markdown(json_string)
|
|
assert parsed == {"foo": "bar"}
|