Skip to content

Commit

Permalink
fix(formatter): leave empty lines in descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
fyhertz committed Jan 21, 2022
1 parent 02e1ba9 commit 9bdaaf6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/ops2deb/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def sort_blueprints(blueprints: List[Blueprint]) -> List[Blueprint]:

def format_description(description: str) -> str:
lines: List[str] = []
description = description.strip("\n ")
for line in description.split("\n"):
lines.extend(wrap(line, width=79))
lines.extend(wrap(line, width=79) or [""])
return "\n".join(lines)


Expand Down
28 changes: 22 additions & 6 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest

from ops2deb.formatter import format_description

description_with_empty_line = """\
description_with_empty_line = """
This thing does the following:
- It does this
Expand All @@ -12,16 +14,30 @@
"""


def test_format_description_should_remove_empty_lines():
def test_format_description_should_only_remove_empty_lines_at_start_or_end():
result = format_description(description_with_empty_line)
assert "" not in result.split("\n")
assert result[0] != "\n"
assert result[-1] != "\n"
assert "\n" in result


def test_format_description_should_be_idempotent():
result = format_description(description_with_empty_line)
assert format_description(result) == result
def test_format_description_should_remove_trailing_spaces():
lines = description_with_empty_line.split("\n")
lines = [line + " " for line in lines]
description_with_trailing_spaces = "\n".join(lines)
result = format_description(description_with_trailing_spaces).split("\n")
assert result[0][-1] == ":"
assert result[1] == ""


def test_format_description_should_wrap_long_lines():
result = format_description(description_with_long_line)
assert len(result.split("\n")) == 2


@pytest.mark.parametrize(
"description", [description_with_empty_line, description_with_long_line]
)
def test_format_description_should_be_idempotent(description):
result = format_description(description)
assert format_description(result) == result

0 comments on commit 9bdaaf6

Please sign in to comment.