Skip to content

Commit

Permalink
Merge pull request #21 from callowayproject/20-versionnotfounderror-d…
Browse files Browse the repository at this point in the history
…oes-not-always-display-the-correct-version-serialization

Fixes reporting the wrong version missing in a file
  • Loading branch information
coordt authored Jun 14, 2023
2 parents fc491fc + 7d17073 commit c896fb0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.270'
rev: 'v0.0.272'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
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)
2 changes: 1 addition & 1 deletion bumpversion/version_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _serialize(
except KeyError as e:
missing_key = getattr(e, "message", e.args[0])
raise MissingValueError(
f"Did not find key {missing_key!r} in {repr(version)} when serializing version number"
f"Did not find key {missing_key!r} in {version!r} when serializing version number"
) from e

keys_needing_representation = set()
Expand Down
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 c896fb0

Please sign in to comment.