Skip to content

Commit 0a8f4b9

Browse files
author
Coding Agent
committed
https://github.com/Penify-dev/PyDocSmith.git
1 parent 86cf43e commit 0a8f4b9

1 file changed

Lines changed: 146 additions & 1 deletion

File tree

PyDocSmith/tests/test_integration.py

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,149 @@ def test_cross_style_composition():
295295
# Should be valid reST
296296
reparsed = parse(rest_composed, style=DocstringStyle.REST)
297297
assert reparsed.short_description == parsed.short_description
298-
assert len(reparsed.params) == len(parsed.params)
298+
assert len(reparsed.params) == len(parsed.params)
299+
300+
301+
def test_empty_docstring():
302+
"""Test parsing an empty docstring."""
303+
empty_doc = ""
304+
305+
parsed = parse(empty_doc)
306+
assert parsed.short_description == ""
307+
assert parsed.long_description == ""
308+
assert len(parsed.params) == 0
309+
assert parsed.returns is None
310+
assert len(parsed.raises) == 0
311+
312+
313+
def test_short_description_only():
314+
"""Test parsing a docstring with only short description."""
315+
short_doc = "This is a short description."
316+
317+
parsed = parse(short_doc)
318+
assert parsed.short_description == "This is a short description."
319+
assert parsed.long_description == ""
320+
assert len(parsed.params) == 0
321+
322+
323+
def test_parse_from_object_method():
324+
"""Test parse_from_object with a class method."""
325+
class SampleClass:
326+
def method(self, x: int, y: str = "default"):
327+
"""Method description.
328+
329+
Args:
330+
x: Integer parameter
331+
y: String parameter with default
332+
333+
Returns:
334+
str: Result
335+
"""
336+
return f"{x}_{y}"
337+
338+
parsed = parse_from_object(SampleClass.method)
339+
340+
assert "Method description" in parsed.short_description
341+
assert len(parsed.params) == 2
342+
assert parsed.params[0].arg_name == "x"
343+
assert parsed.params[1].arg_name == "y"
344+
assert parsed.returns.description == "Result"
345+
346+
347+
def test_combine_docstrings_conflicting_params():
348+
"""Test combining docstrings with conflicting parameter descriptions."""
349+
doc1 = """Function doc.
350+
351+
Args:
352+
x: First description of x
353+
"""
354+
355+
doc2 = """Another doc.
356+
357+
Args:
358+
x: Second description of x
359+
y: Description of y
360+
"""
361+
362+
combined = combine_docstrings([doc1, doc2])
363+
364+
parsed = parse(combined, style=DocstringStyle.GOOGLE)
365+
366+
# Should have both params, but x might be from first or second
367+
assert len(parsed.params) >= 1
368+
assert any(p.arg_name == "x" for p in parsed.params)
369+
assert any(p.arg_name == "y" for p in parsed.params)
370+
371+
372+
def test_docstring_with_examples():
373+
"""Test parsing docstring with examples section."""
374+
doc = """Function description.
375+
376+
Args:
377+
x: Input value
378+
379+
Examples:
380+
>>> func(1)
381+
2
382+
"""
383+
384+
parsed = parse(doc, style=DocstringStyle.GOOGLE)
385+
386+
assert parsed.short_description == "Function description."
387+
assert len(parsed.params) == 1
388+
assert parsed.params[0].arg_name == "x"
389+
390+
391+
def test_parse_from_object_property():
392+
"""Test parse_from_object with a property."""
393+
class SampleClass:
394+
@property
395+
def prop(self):
396+
"""Property description.
397+
398+
Returns:
399+
int: The value
400+
"""
401+
return 42
402+
403+
parsed = parse_from_object(SampleClass.prop)
404+
405+
assert "Property description" in parsed.short_description
406+
assert parsed.returns.description == "The value"
407+
408+
409+
def test_invalid_style_error():
410+
"""Test error handling with invalid style."""
411+
doc = "Some docstring"
412+
413+
# This should work with AUTO
414+
parsed = parse(doc, style=DocstringStyle.AUTO)
415+
assert parsed is not None
416+
417+
418+
def test_minimal_round_trip():
419+
"""Test round-trip with minimal docstring."""
420+
minimal_doc = "Minimal doc."
421+
422+
parsed = parse(minimal_doc)
423+
composed = compose(parsed, style=DocstringStyle.GOOGLE)
424+
reparsed = parse(composed, style=DocstringStyle.GOOGLE)
425+
426+
assert reparsed.short_description == parsed.short_description
427+
428+
429+
def test_docstring_with_notes():
430+
"""Test parsing docstring with notes section."""
431+
doc = """Function description.
432+
433+
Args:
434+
x: Input
435+
436+
Notes:
437+
This is a note.
438+
"""
439+
440+
parsed = parse(doc, style=DocstringStyle.GOOGLE)
441+
442+
assert parsed.short_description == "Function description."
443+
assert len(parsed.params) == 1

0 commit comments

Comments
 (0)