|
9 | 9 | from unittest import mock
|
10 | 10 |
|
11 | 11 | from flaky import flaky
|
| 12 | +from docstring_to_markdown import UnknownFormatError |
12 | 13 |
|
13 | 14 | from pylsp import _utils
|
14 | 15 | from pylsp.python_lsp import PythonLSPServer, start_io_lang_server
|
@@ -154,3 +155,53 @@ def test_clip_column():
|
154 | 155 | assert _utils.clip_column(2, ["123\n", "123"], 0) == 2
|
155 | 156 | assert _utils.clip_column(3, ["123\n", "123"], 0) == 3
|
156 | 157 | assert _utils.clip_column(4, ["123\n", "123"], 1) == 3
|
| 158 | + |
| 159 | + |
| 160 | +@mock.patch("docstring_to_markdown.convert") |
| 161 | +def test_format_docstring_valid_rst_signature(mock_convert): |
| 162 | + """Test that a valid RST docstring includes the function signature.""" |
| 163 | + docstring = """A function docstring. |
| 164 | +
|
| 165 | + Parameters |
| 166 | + ---------- |
| 167 | + a : str, something |
| 168 | + """ |
| 169 | + |
| 170 | + # Mock the return value to avoid depedency on the real thing |
| 171 | + mock_convert.return_value = """A function docstring. |
| 172 | +
|
| 173 | + #### Parameters |
| 174 | +
|
| 175 | + - `a`: str, something |
| 176 | + """ |
| 177 | + |
| 178 | + markdown = _utils.format_docstring( |
| 179 | + docstring, |
| 180 | + "markdown", |
| 181 | + ["something(a: str) -> str"], |
| 182 | + )["value"] |
| 183 | + |
| 184 | + assert markdown.startswith( |
| 185 | + _utils.wrap_signature("something(a: str) -> str"), |
| 186 | + ) |
| 187 | + |
| 188 | + |
| 189 | +@mock.patch("docstring_to_markdown.convert", side_effect=UnknownFormatError) |
| 190 | +def test_format_docstring_invalid_rst_signature(_): |
| 191 | + """Test that an invalid RST docstring includes the function signature.""" |
| 192 | + docstring = """A function docstring. |
| 193 | +
|
| 194 | + Parameters |
| 195 | + ---------- |
| 196 | + a : str, something |
| 197 | + """ |
| 198 | + |
| 199 | + markdown = _utils.format_docstring( |
| 200 | + docstring, |
| 201 | + "markdown", |
| 202 | + ["something(a: str) -> str"], |
| 203 | + )["value"] |
| 204 | + |
| 205 | + assert markdown.startswith( |
| 206 | + _utils.wrap_signature("something(a: str) -> str"), |
| 207 | + ) |
0 commit comments