Skip to content

Commit efb04e9

Browse files
committed
Fixes reporting the wrong version missing in a file
- Fixes issue #20 - Renders the correct `current_version` for each file being modified.
1 parent fc491fc commit efb04e9

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

bumpversion/files.py

+1
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,5 @@ def _check_files_contain_version(
209209
", ".join({str(f.path) for f in files}),
210210
)
211211
for f in files:
212+
context["current_version"] = f.version_config.serialize(current_version, context)
212213
f.contains_version(current_version, context)

tests/test_files.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from bumpversion import exceptions, files
1111
from bumpversion.utils import get_context
12+
from bumpversion.exceptions import VersionNotFoundError
1213
from tests.conftest import get_config_data, inside_dir
1314

1415

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

155156

156-
def test_issue_14(tmp_path: Path):
157+
def test_raises_correct_missing_version_string(tmp_path: Path):
157158
full_vers_path = tmp_path / "FULL_VERSION.txt"
158159
full_vers_path.write_text("3.1.0-rc+build.1031")
159160
assembly_path = tmp_path / "AssemblyInfo.cs"
160161
assembly_path.write_text(
161162
'[assembly: AssemblyFileVersion("3.1.0-rc+build.1031")]\n' '[assembly: AssemblyVersion("3.1.1031.0")]'
162163
)
163164
csv_path = tmp_path / "Version.csv"
164-
csv_path.write_text("1;3;1;0;rc;build.1031")
165+
csv_path.write_text("1;3-1;0;rc;build.1031")
165166

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

214215
ctx = get_context(conf)
215216

216-
for file_cfg in conf.files:
217-
cfg_file = files.ConfiguredFile(file_cfg, version_config)
218-
cfg_file.replace_version(current_version, major_version, ctx)
217+
configured_files = [files.ConfiguredFile(file_cfg, version_config) for file_cfg in conf.files]
219218

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

225223

226224
def test_search_replace_to_avoid_updating_unconcerned_lines(tmp_path: Path):

0 commit comments

Comments
 (0)