Skip to content

Commit

Permalink
fix: adding newlines around wrapped URL (#182)
Browse files Browse the repository at this point in the history
* fix: adding newlines around wrapped URL

* test: for adding newlines around wrapped URL
  • Loading branch information
weibullguy committed Apr 23, 2023
1 parent 8afd968 commit 504e950
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/docformatter/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def description_to_list(
if _text:
_lines.extend(_text)
_lines.append("")
with contextlib.suppress(IndexError):
if _lines[-2] == _lines[-1] == "":
_lines.pop(-1)

return _lines

Expand Down Expand Up @@ -335,6 +338,9 @@ def do_split_description(
)
)

if _lines[-1] == "":
_lines.pop(-1)

# Add the URL.
_lines.append(
f"{do_clean_url(text[_idx[0] : _idx[1]], indentation)}"
Expand Down
55 changes: 53 additions & 2 deletions tests/test_format_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,57 @@ def test_format_docstring_with_short_link(
INDENTATION, docstring.strip()
)

@pytest.mark.unit
@pytest.mark.parametrize(
"args",
[["--wrap-descriptions", "88", "--wrap-summaries", "88", ""]],
)
def test_format_docstring_link_only_one_newline_after_link(
self,
test_args,
args,
):
"""Links should have no newline before them and only one after.
See issue #180.
"""
uut = Formatter(
test_args,
sys.stderr,
sys.stdin,
sys.stdout,
)

docstring = '''\
"""Django settings for webapp project.
Generated by 'django-admin startproject' using Django 4.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""\
'''

assert '''\
"""Django settings for webapp project.
Generated by 'django-admin startproject' using Django 4.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""\
''' == uut._do_format_docstring(
INDENTATION, docstring.strip()
)

@pytest.mark.unit
@pytest.mark.parametrize("args", [[""]])
def test_format_docstring_with_class_attributes(self, test_args, args):
Expand Down Expand Up @@ -1329,10 +1380,10 @@ class TestClass:

@pytest.mark.unit
@pytest.mark.parametrize("args", [[""]])
def test_format_docstring_no_blank_in_summary_with_symbol(
def test_format_docstring_no_newline_in_summary_with_symbol(
self, test_args, args
):
"""Wrap long class attribute docstrings.
"""Wrap summary with symbol should not add newline.
See issue #79.
"""
Expand Down

0 comments on commit 504e950

Please sign in to comment.