-
Notifications
You must be signed in to change notification settings - Fork 16.3k
/
Copy pathtest_boolean_parser.py
46 lines (33 loc) · 1.1 KB
/
test_boolean_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pytest
from langchain.output_parsers.boolean import BooleanOutputParser
def test_boolean_output_parser_parse() -> None:
parser = BooleanOutputParser()
# Test valid input
result = parser.parse("YES")
assert result is True
# Test valid input
result = parser.parse("NO")
assert result is False
# Test valid input
result = parser.parse("yes")
assert result is True
# Test valid input
result = parser.parse("no")
assert result is False
# Test valid input
result = parser.parse("Not relevant (NO)")
assert result is False
# Test valid input
result = parser.parse("NOW this is relevant (YES)")
assert result is True
# Test ambiguous input
with pytest.raises(ValueError):
parser.parse("YES NO")
with pytest.raises(ValueError):
parser.parse("NO YES")
# Bad input
with pytest.raises(ValueError):
parser.parse("BOOM")
def test_boolean_output_parser_output_type() -> None:
"""Test the output type of the boolean output parser is a boolean."""
assert BooleanOutputParser().OutputType is bool