Skip to content

Commit c1ef3b2

Browse files
committed
Fixed file configuration overrides
Fixes #55 The file config was ignoring falsey values when constructing the dict. It now ignores `None` values.
1 parent d5b9ce0 commit c1ef3b2

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

bumpversion/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_all_file_configs(config_dict: dict) -> List[FileConfig]:
122122
"ignore_missing_version": config_dict["ignore_missing_version"],
123123
"no_regex": config_dict["no_regex"],
124124
}
125-
files = [{k: v for k, v in filecfg.items() if v} for filecfg in config_dict["files"]]
125+
files = [{k: v for k, v in filecfg.items() if v is not None} for filecfg in config_dict["files"]]
126126
for f in files:
127127
f.update({k: v for k, v in defaults.items() if k not in f})
128128
return [FileConfig(**f) for f in files]

docsrc/reference/configuration.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ This is useful if there is the remotest possibility that the current version num
236236

237237
This is the template to create the string that will replace the current version number in the file.
238238

239-
### `ingore_missing_version`
239+
### `ignore_missing_version`
240240
:required: No
241241

242242
:default: `False`
@@ -447,10 +447,10 @@ This is an override to the default template string how to search for the string
447447

448448
This is an override to the template to create the string that will replace the current version number in the file.
449449

450-
### `ingore_missing_version`
450+
### `ignore_missing_version`
451451
:required: No
452452

453-
:default: The value configured in the global `ingore_missing_version` field
453+
:default: The value configured in the global `ignore_missing_version` field
454454

455455
:type: boolean
456456

tests/test_files.py

+23-10
Original file line numberDiff line numberDiff line change
@@ -349,24 +349,37 @@ def test_multi_line_search_is_found(tmp_path: Path) -> None:
349349
assert alphabet_path.read_text() == "A\nB\nC\n10.0.0\n"
350350

351351

352-
def test_ignore_missing_version(tmp_path: Path) -> None:
352+
@pytest.mark.parametrize(
353+
["global_value", "file_value", "should_raise"],
354+
[
355+
param(True, True, False, id="ignore global and file"),
356+
param(True, False, True, id="ignore global only"),
357+
param(False, True, False, id="ignore file only"),
358+
param(False, False, True, id="ignore none"),
359+
],
360+
)
361+
def test_ignore_missing_version(global_value: bool, file_value: bool, should_raise: bool, tmp_path: Path) -> None:
353362
"""If the version is not found in the file, do nothing."""
354363
# Arrange
355364
version_path = tmp_path / Path("VERSION")
356365
version_path.write_text("1.2.3")
357366

358367
overrides = {
359368
"current_version": "1.2.5",
360-
"ignore_missing_version": True,
361-
"files": [{"filename": str(version_path)}],
369+
"ignore_missing_version": global_value,
370+
"files": [{"filename": str(version_path), "ignore_missing_version": file_value}],
362371
}
363-
conf, version_config, current_version = get_config_data(overrides)
364-
assert conf.ignore_missing_version is True
365-
new_version = current_version.bump("patch", version_config.order)
366-
cfg_files = [files.ConfiguredFile(file_cfg, version_config) for file_cfg in conf.files]
367-
368-
# Act
369-
files.modify_files(cfg_files, current_version, new_version, get_context(conf))
372+
with inside_dir(tmp_path):
373+
conf, version_config, current_version = get_config_data(overrides)
374+
new_version = current_version.bump("patch", version_config.order)
375+
cfg_files = [files.ConfiguredFile(file_cfg, version_config) for file_cfg in conf.files]
376+
377+
# Act
378+
if should_raise:
379+
with pytest.raises(VersionNotFoundError):
380+
files.modify_files(cfg_files, current_version, new_version, get_context(conf))
381+
else:
382+
files.modify_files(cfg_files, current_version, new_version, get_context(conf))
370383

371384
# Assert
372385
assert version_path.read_text() == "1.2.3"

0 commit comments

Comments
 (0)