Skip to content

Commit

Permalink
fix: adding blank line in summary with symbol (#179)
Browse files Browse the repository at this point in the history
* fix: don't add blank line in summary with symbol

* test: add test for blank line in summary with symbol
  • Loading branch information
weibullguy committed Apr 22, 2023
1 parent c89bead commit 2b42c28
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/docformatter/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ def split_summary_and_description(contents):
for index in range(1, len(split_lines)):
# Empty line separation would indicate the rest is the description or
# symbol on second line probably is a description with a list.
if not split_lines[index].strip() or is_probably_beginning_of_sentence(
split_lines[index]
if not split_lines[index].strip() or (
index + 1 < len(split_lines)
and is_probably_beginning_of_sentence(split_lines[index + 1])
):
return (
"\n".join(split_lines[:index]).strip(),
Expand Down
66 changes: 47 additions & 19 deletions tests/test_format_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,11 @@ def test_format_docstring_leave_link_only_docstring_alone(

@pytest.mark.unit
@pytest.mark.parametrize("args", [[""]])
def test_format_docstring_leave_blank_line_after_variable_def(self,
test_args,
args,):
def test_format_docstring_leave_blank_line_after_variable_def(
self,
test_args,
args,
):
"""Leave blank lines after any variable beginning with 'def'.
See issue #156.
Expand Down Expand Up @@ -368,9 +370,11 @@ class AcceptLanguageHeader(ExtendedSchemaNode): \

@pytest.mark.unit
@pytest.mark.parametrize("args", [[""]])
def test_format_docstring_leave_blank_line_after_comment(self,
test_args,
args,):
def test_format_docstring_leave_blank_line_after_comment(
self,
test_args,
args,
):
"""Leave blank lines after docstring followed by a comment.
See issue #176.
Expand Down Expand Up @@ -1029,8 +1033,8 @@ def test_format_docstring_with_short_inline_link(
A larger description that ends here.
"""\
''' == uut._do_format_docstring(
INDENTATION, docstring.strip()
)
INDENTATION, docstring.strip()
)

@pytest.mark.unit
@pytest.mark.parametrize(
Expand Down Expand Up @@ -1124,8 +1128,9 @@ def test_format_docstring_with_target_links(
.. _logspace API: https://numpy.org/doc/stable/reference/generated/numpy.logspace.html
"""\
''' == uut._do_format_docstring(
INDENTATION, docstring.strip()
)
INDENTATION, docstring.strip()
)

@pytest.mark.unit
@pytest.mark.parametrize(
"args",
Expand Down Expand Up @@ -1201,23 +1206,23 @@ def test_format_docstring_keep_inline_link_together(
`custom types provided by Click <https://click.palletsprojects.com/en/8.1.x/api/?highlight=intrange#types>`_.
"""\
''' == uut._do_format_docstring(
INDENTATION, docstring.strip()
)
INDENTATION, docstring.strip()
)

@pytest.mark.unit
@pytest.mark.parametrize(
"args",
[["--wrap-descriptions", "88", ""]],
)
def test_format_docstring_keep_inline_link_together_two_paragraphs(
self,
test_args,
args,
self,
test_args,
args,
):
"""Keep in-line links together with the display text.
If there is another paragraph following the in-line link, don't strip
the newline in between.
If there is another paragraph following the in-line link, don't
strip the newline in between.
See issue #157.
"""
Expand Down Expand Up @@ -1253,8 +1258,8 @@ def test_format_docstring_keep_inline_link_together_two_paragraphs(
precedence over any values from the config file.
"""\
''' == uut._do_format_docstring(
INDENTATION, docstring.strip()
)
INDENTATION, docstring.strip()
)

@pytest.mark.unit
@pytest.mark.parametrize(
Expand Down Expand Up @@ -1322,6 +1327,29 @@ class TestClass:
'''
)

@pytest.mark.unit
@pytest.mark.parametrize("args", [[""]])
def test_format_docstring_no_blank_in_summary_with_symbol(
self, test_args, args
):
"""Wrap long class attribute docstrings.
See issue #79.
"""
uut = Formatter(
test_args,
sys.stderr,
sys.stdin,
sys.stdout,
)

docstring = '''\
def function2():
"""Hello yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet
-v."""
'''
assert docstring == uut._do_format_code(docstring)


class TestFormatStyleOptions:
"""Class for testing format_docstring() when requesting style options."""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_string_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ def test_split_summary_and_description_with_capital(self):
def test_split_summary_and_description_with_list_on_other_line(self):
""""""
assert (
"Test\n test",
" @blah",
"Test",
" test\n @blah",
) == docformatter.split_summary_and_description(
"""\
Test
Expand Down

0 comments on commit 2b42c28

Please sign in to comment.