Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes reporting the wrong version missing in a file #21

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
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