Skip to content

Commit 6173587

Browse files
committed
test: cover defensive branches in docstring parser
The MCP repo enforces 100% test coverage. Add two tests that exercise the previously uncovered defensive branches in _parse_param_line: - test_param_line_with_unclosed_parenthesis covers the end_idx == -1 fallback when a type annotation has no closing paren - test_param_line_starting_with_non_word covers the regex no-match fallback for lines that do not begin with a word character
1 parent c669441 commit 6173587

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/server/mcpserver/test_docstring.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,31 @@ def test_complex_type_annotation_in_param():
176176
"""
177177
_, params = parse_docstring(docstring)
178178
assert params == {"data": "Input data."}
179+
180+
181+
def test_param_line_with_unclosed_parenthesis():
182+
"""An unclosed type annotation should be treated as a non-param line."""
183+
docstring = """
184+
Function.
185+
186+
Args:
187+
broken (unclosed type: description
188+
ok: A real param.
189+
"""
190+
summary, params = parse_docstring(docstring)
191+
assert summary == "Function."
192+
assert params == {"ok": "A real param."}
193+
194+
195+
def test_param_line_starting_with_non_word():
196+
"""A line that does not start with a word character should be skipped."""
197+
docstring = """
198+
Function.
199+
200+
Args:
201+
: orphan colon line
202+
x: Real param.
203+
"""
204+
summary, params = parse_docstring(docstring)
205+
assert summary == "Function."
206+
assert params == {"x": "Real param."}

0 commit comments

Comments
 (0)