Skip to content

Commit

Permalink
Fixes reporting the wrong version missing in a file
Browse files Browse the repository at this point in the history
- Fixes issue #20
- Renders the correct `current_version` for each file being modified.
  • Loading branch information
coordt committed Jun 14, 2023
1 parent fc491fc commit efb04e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions bumpversion/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,5 @@ def _check_files_contain_version(
", ".join({str(f.path) for f in files}),
)
for f in files:
context["current_version"] = f.version_config.serialize(current_version, context)
f.contains_version(current_version, context)
16 changes: 7 additions & 9 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from bumpversion import exceptions, files
from bumpversion.utils import get_context
from bumpversion.exceptions import VersionNotFoundError
from tests.conftest import get_config_data, inside_dir


Expand Down Expand Up @@ -153,15 +154,15 @@ def test_multi_file_configuration(tmp_path: Path):
assert build_num_path.read_text() == "2.0.1+jane+38945"


def test_issue_14(tmp_path: Path):
def test_raises_correct_missing_version_string(tmp_path: Path):
full_vers_path = tmp_path / "FULL_VERSION.txt"
full_vers_path.write_text("3.1.0-rc+build.1031")
assembly_path = tmp_path / "AssemblyInfo.cs"
assembly_path.write_text(
'[assembly: AssemblyFileVersion("3.1.0-rc+build.1031")]\n' '[assembly: AssemblyVersion("3.1.1031.0")]'
)
csv_path = tmp_path / "Version.csv"
csv_path.write_text("1;3;1;0;rc;build.1031")
csv_path.write_text("1;3-1;0;rc;build.1031")

overrides = {
"current_version": "3.1.0-rc+build.1031",
Expand Down Expand Up @@ -213,14 +214,11 @@ def test_issue_14(tmp_path: Path):

ctx = get_context(conf)

for file_cfg in conf.files:
cfg_file = files.ConfiguredFile(file_cfg, version_config)
cfg_file.replace_version(current_version, major_version, ctx)
configured_files = [files.ConfiguredFile(file_cfg, version_config) for file_cfg in conf.files]

assert full_vers_path.read_text() == "3.1.1-beta+build.1031"
expected = '[assembly: AssemblyFileVersion("3.1.1-beta+build.1031")]\n[assembly: AssemblyVersion("3.1.1031.1")]'
assert assembly_path.read_text() == expected
assert csv_path.read_text() == "1;3;1;1;beta;build.1031"
with pytest.raises(VersionNotFoundError) as e:
files.modify_files(configured_files, current_version, major_version, ctx)
assert e.message.startswith("Did not find '1;3;1;0;rc;build.1031'")


def test_search_replace_to_avoid_updating_unconcerned_lines(tmp_path: Path):
Expand Down

0 comments on commit efb04e9

Please sign in to comment.