8
8
from .test_prompt import _PromptOutput
9
9
10
10
11
- def test_prompt_with_str_output ():
11
+ async def test_prompt_with_str_output ():
12
12
"""Test a prompt with a string output."""
13
13
14
14
class TestPrompt (Prompt [None , str ]): # pylint: disable=unused-variable
@@ -17,10 +17,10 @@ class TestPrompt(Prompt[None, str]): # pylint: disable=unused-variable
17
17
user_prompt = "Hello"
18
18
19
19
prompt = TestPrompt ()
20
- assert prompt .parse_response ("Hi" ) == "Hi"
20
+ assert await prompt .parse_response ("Hi" ) == "Hi"
21
21
22
22
23
- def test_prompt_with_int_output ():
23
+ async def test_prompt_with_int_output ():
24
24
"""Test a prompt with an int output."""
25
25
26
26
class TestPrompt (Prompt [None , int ]): # pylint: disable=unused-variable
@@ -29,13 +29,13 @@ class TestPrompt(Prompt[None, int]): # pylint: disable=unused-variable
29
29
user_prompt = "Hello"
30
30
31
31
prompt = TestPrompt ()
32
- assert prompt .parse_response ("1" ) == 1
32
+ assert await prompt .parse_response ("1" ) == 1
33
33
34
34
with pytest .raises (ResponseParsingError ):
35
- prompt .parse_response ("a" )
35
+ await prompt .parse_response ("a" )
36
36
37
37
38
- def test_prompt_with_model_output ():
38
+ async def test_prompt_with_model_output ():
39
39
"""Test a prompt with a model output."""
40
40
41
41
class TestPrompt (Prompt [None , _PromptOutput ]): # pylint: disable=unused-variable
@@ -44,15 +44,15 @@ class TestPrompt(Prompt[None, _PromptOutput]): # pylint: disable=unused-variabl
44
44
user_prompt = "Hello"
45
45
46
46
prompt = TestPrompt ()
47
- assert prompt .parse_response ('{"song_title": "Hello", "song_lyrics": "World"}' ) == _PromptOutput (
47
+ assert await prompt .parse_response ('{"song_title": "Hello", "song_lyrics": "World"}' ) == _PromptOutput (
48
48
song_title = "Hello" , song_lyrics = "World"
49
49
)
50
50
51
51
with pytest .raises (ResponseParsingError ):
52
- prompt .parse_response ('{"song_title": "Hello"}' )
52
+ await prompt .parse_response ('{"song_title": "Hello"}' )
53
53
54
54
55
- def test_prompt_with_float_output ():
55
+ async def test_prompt_with_float_output ():
56
56
"""Test a prompt with a float output."""
57
57
58
58
class TestPrompt (Prompt [None , float ]): # pylint: disable=unused-variable
@@ -61,13 +61,13 @@ class TestPrompt(Prompt[None, float]): # pylint: disable=unused-variable
61
61
user_prompt = "Hello"
62
62
63
63
prompt = TestPrompt ()
64
- assert prompt .parse_response ("1.0" ) == 1.0
64
+ assert await prompt .parse_response ("1.0" ) == 1.0
65
65
66
66
with pytest .raises (ResponseParsingError ):
67
- prompt .parse_response ("a" )
67
+ await prompt .parse_response ("a" )
68
68
69
69
70
- def test_prompt_with_bool_output ():
70
+ async def test_prompt_with_bool_output ():
71
71
"""Test a prompt with a bool output."""
72
72
73
73
class TestPrompt (Prompt [None , bool ]): # pylint: disable=unused-variable
@@ -76,14 +76,14 @@ class TestPrompt(Prompt[None, bool]): # pylint: disable=unused-variable
76
76
user_prompt = "Hello"
77
77
78
78
prompt = TestPrompt ()
79
- assert prompt .parse_response ("true" ) is True
80
- assert prompt .parse_response ("false" ) is False
79
+ assert await prompt .parse_response ("true" ) is True
80
+ assert await prompt .parse_response ("false" ) is False
81
81
82
82
with pytest .raises (ResponseParsingError ):
83
- prompt .parse_response ("a" )
83
+ await prompt .parse_response ("a" )
84
84
85
85
86
- def test_prompt_with_int_and_custom_parser ():
86
+ async def test_prompt_with_int_and_custom_parser ():
87
87
"""Test a prompt with an int output and a custom parser."""
88
88
89
89
class TestPrompt (Prompt [None , int ]): # pylint: disable=unused-variable
@@ -111,10 +111,10 @@ def response_parser(response: str) -> int:
111
111
raise ResponseParsingError ("Could not parse response" )
112
112
113
113
prompt = TestPrompt ()
114
- assert prompt .parse_response ("abcd k2" ) == 2
114
+ assert await prompt .parse_response ("abcd k2" ) == 2
115
115
116
116
with pytest .raises (ResponseParsingError ):
117
- prompt .parse_response ("a" )
117
+ await prompt .parse_response ("a" )
118
118
119
119
120
120
def test_prompt_with_unknown_output_and_no_parser ():
@@ -127,7 +127,7 @@ class TestPrompt(Prompt[None, list]): # pylint: disable=unused-variable
127
127
user_prompt = "Hello"
128
128
129
129
130
- def test_prompt_with_unknown_output_and_custom_parser ():
130
+ async def test_prompt_with_unknown_output_and_custom_parser ():
131
131
"""Test a prompt with an output type that doesn't have a default parser but has a custom parser."""
132
132
133
133
class TestPrompt (Prompt [None , list ]): # pylint: disable=unused-variable
@@ -152,5 +152,5 @@ def response_parser(response: str) -> list:
152
152
return response .split ()
153
153
154
154
prompt = TestPrompt ()
155
- assert prompt .parse_response ("Hello World" ) == ["Hello" , "World" ]
156
- assert prompt .parse_response ("Hello" ) == ["Hello" ]
155
+ assert await prompt .parse_response ("Hello World" ) == ["Hello" , "World" ]
156
+ assert await prompt .parse_response ("Hello" ) == ["Hello" ]
0 commit comments