2023-08-25 08:47:17 +00:00
|
|
|
from typing import List
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2024-05-08 20:46:52 +00:00
|
|
|
from langchain_community.retrievers.web_research import QuestionListOutputParser
|
2023-08-25 08:47:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"text,expected",
|
|
|
|
(
|
|
|
|
(
|
|
|
|
"1. Line one.\n",
|
|
|
|
["1. Line one.\n"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"1. Line one.",
|
|
|
|
["1. Line one."],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"1. Line one.\n2. Line two.\n",
|
|
|
|
["1. Line one.\n", "2. Line two.\n"],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"1. Line one.\n2. Line two.",
|
|
|
|
["1. Line one.\n", "2. Line two."],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"1. Line one.\n2. Line two.\n3. Line three.",
|
|
|
|
["1. Line one.\n", "2. Line two.\n", "3. Line three."],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
def test_list_output_parser(text: str, expected: List[str]) -> None:
|
|
|
|
parser = QuestionListOutputParser()
|
|
|
|
result = parser.parse(text)
|
2024-02-13 06:52:07 +00:00
|
|
|
assert result == expected
|