Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/commentedconfigparser/commentedconfigparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,7 @@ def _restore_comments(self, content: str) -> str:

rendered.append(line + "\n")

# Remove extra trailing newline
rendered[-1] = rendered[-1].rstrip()

return "".join(rendered)
6 changes: 3 additions & 3 deletions tests/commentedconfigparser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_regression_read_dict_loads_normally() -> None:

def test_regression_write_normally() -> None:
cc = CommentedConfigParser()
expected = "[TEST]\ntest=pass\n\n"
expected = "[TEST]\ntest=pass\n"
cc.read_string(expected)
mock_file = StringIO()

Expand All @@ -139,7 +139,7 @@ def test_regression_write_normally() -> None:

def test_write_with_no_comments() -> None:
cc = CommentedConfigParser()
expected = "[TEST]\ntest=pass\n\n"
expected = "[TEST]\ntest=pass\n"
cc.read_dict({"TEST": {"test": "pass"}})
mock_file = StringIO()

Expand Down Expand Up @@ -181,7 +181,7 @@ def test_issue_46_duplicating_sections(tmp_path: Path) -> None:
# https://github.com/Preocts/commented-configparser/issues/46
tmp_file = tmp_path / "issue46_test_file.ini"
starting_config = "[example]\nfoo = 0\n"
expected = "[example]\nfoo = 9\n\n"
expected = "[example]\nfoo = 9\n"
tmp_file.write_text(starting_config, "utf-8")
cc = CommentedConfigParser()
cc.read(tmp_file)
Expand Down
1 change: 0 additions & 1 deletion tests/empty_comments_expected.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ bar = foo

[BIZ]
baz = bar

1 change: 0 additions & 1 deletion tests/header_expected.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@
foo = bar
# Comment here
bar = foo

1 change: 0 additions & 1 deletion tests/multi_expected.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ foo = bar
unique to multi02 = foo
; A nice little comment here from multi01
unique to multi01 = foo

1 change: 0 additions & 1 deletion tests/pydocs_expected.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ multiline_values = are
deeper than the first line
of a value
# Did I mention we can indent comments, too?

1 change: 0 additions & 1 deletion tests/regression_original_expected.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ multi-line =
value03
closing = 0
# Trailing comment