|
13 | 13 | _RunnableStreamAgent, # pyright: ignore [reportPrivateUsage]
|
14 | 14 | _RunnableStreamOutputOnlyAgent, # pyright: ignore [reportPrivateUsage]
|
15 | 15 | agent_wrapper,
|
| 16 | + clean_docstring, |
16 | 17 | extract_fn_spec,
|
17 | 18 | get_generic_args,
|
18 | 19 | is_async_iterator,
|
@@ -113,3 +114,58 @@ async def test_fn_stream_output_only(self, mock_api_client: Mock):
|
113 | 114 | assert len(chunks) == 1
|
114 | 115 | assert isinstance(chunks[0], HelloTaskOutput)
|
115 | 116 | assert chunks[0] == HelloTaskOutput(message="Hello, World!")
|
| 117 | + |
| 118 | + |
| 119 | +def test_clean_docstring(): |
| 120 | + # Test empty docstring |
| 121 | + assert clean_docstring("") == "" |
| 122 | + assert clean_docstring(None) == "" |
| 123 | + |
| 124 | + # Test single line docstring |
| 125 | + assert clean_docstring("Hello world") == "Hello world" |
| 126 | + assert clean_docstring(" Hello world ") == "Hello world" |
| 127 | + |
| 128 | + # Test docstring with empty lines at start/end |
| 129 | + assert clean_docstring(""" |
| 130 | +
|
| 131 | + Hello world |
| 132 | +
|
| 133 | + """) == "Hello world" |
| 134 | + |
| 135 | + # Test multi-line docstring with indentation |
| 136 | + assert clean_docstring(""" |
| 137 | + First line |
| 138 | + Second line |
| 139 | + Indented line |
| 140 | + Last line |
| 141 | + """) == "First line\nSecond line\n Indented line\nLast line" |
| 142 | + |
| 143 | + # Test docstring with empty lines in between |
| 144 | + assert clean_docstring(""" |
| 145 | + First line |
| 146 | +
|
| 147 | + Second line |
| 148 | +
|
| 149 | + Third line |
| 150 | + """) == "First line\n\nSecond line\n\nThird line" |
| 151 | + |
| 152 | + # Test real-world example |
| 153 | + expected = ( |
| 154 | + "Find the capital city of the country where the input city is located.\n\n" |
| 155 | + "Guidelines:\n" |
| 156 | + "1. First identify the country where the input city is located\n" |
| 157 | + "2. Then provide the capital city of that country\n" |
| 158 | + "3. Include an interesting historical or cultural fact about the capital\n" |
| 159 | + "4. Be accurate and precise with geographical information\n" |
| 160 | + "5. If the input city is itself the capital, still provide the information" |
| 161 | + ) |
| 162 | + assert clean_docstring(""" |
| 163 | + Find the capital city of the country where the input city is located. |
| 164 | +
|
| 165 | + Guidelines: |
| 166 | + 1. First identify the country where the input city is located |
| 167 | + 2. Then provide the capital city of that country |
| 168 | + 3. Include an interesting historical or cultural fact about the capital |
| 169 | + 4. Be accurate and precise with geographical information |
| 170 | + 5. If the input city is itself the capital, still provide the information |
| 171 | + """) == expected |
0 commit comments