Skip to content

Commit

Permalink
Fix newlines in config files (c4urself#98)
Browse files Browse the repository at this point in the history
* Fix newlines in config files

* Update tests which previously expected two blank lines, now expect only one

* Update test_retain_newline to explicitly check for a single newline of the right type at the end of the config
  • Loading branch information
kyluca authored and martinmigasiewicz-tomtom committed Nov 17, 2020
1 parent c6460fe commit 319b63c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bumpversion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def _update_config_file(

if write_to_config_file:
with open(config_file, "wt", encoding="utf-8", newline=config_newlines) as f:
f.write(new_config.getvalue())
f.write(new_config.getvalue().strip() + "\n")

except UnicodeEncodeError:
warnings.warn(
Expand Down
8 changes: 6 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ def test_config_file_is_updated(tmpdir):
current_version = 0.0.14
[bumpversion:file:file3]
""" == tmpdir.join(".bumpversion.cfg").read()


Expand Down Expand Up @@ -1990,7 +1989,12 @@ def test_retain_newline(tmpdir, configfile, newline):
main(["major"])

assert newline in tmpdir.join("file.py").read_binary()
assert newline in tmpdir.join(configfile).read_binary()
new_config = tmpdir.join(configfile).read_binary()
assert newline in new_config

# Ensure there is only a single newline (not two) at the end of the file
# and that it is of the right type
assert new_config.endswith(b"[bumpversion:file:file.py]" + newline)


class TestSplitArgsInOptionalAndPositional:
Expand Down

0 comments on commit 319b63c

Please sign in to comment.