Skip to content

Commit

Permalink
Fixed file configuration overrides
Browse files Browse the repository at this point in the history
Fixes #55

The file config was ignoring falsey values when constructing the dict.

It now ignores `None` values.
  • Loading branch information
coordt committed Aug 25, 2023
1 parent d5b9ce0 commit c1ef3b2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bumpversion/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def get_all_file_configs(config_dict: dict) -> List[FileConfig]:
"ignore_missing_version": config_dict["ignore_missing_version"],
"no_regex": config_dict["no_regex"],
}
files = [{k: v for k, v in filecfg.items() if v} for filecfg in config_dict["files"]]
files = [{k: v for k, v in filecfg.items() if v is not None} for filecfg in config_dict["files"]]
for f in files:
f.update({k: v for k, v in defaults.items() if k not in f})
return [FileConfig(**f) for f in files]
Expand Down
6 changes: 3 additions & 3 deletions docsrc/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ This is useful if there is the remotest possibility that the current version num

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

### `ingore_missing_version`
### `ignore_missing_version`
:required: No

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

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

### `ingore_missing_version`
### `ignore_missing_version`
:required: No

:default: The value configured in the global `ingore_missing_version` field
:default: The value configured in the global `ignore_missing_version` field

:type: boolean

Expand Down
33 changes: 23 additions & 10 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,24 +349,37 @@ def test_multi_line_search_is_found(tmp_path: Path) -> None:
assert alphabet_path.read_text() == "A\nB\nC\n10.0.0\n"


def test_ignore_missing_version(tmp_path: Path) -> None:
@pytest.mark.parametrize(
["global_value", "file_value", "should_raise"],
[
param(True, True, False, id="ignore global and file"),
param(True, False, True, id="ignore global only"),
param(False, True, False, id="ignore file only"),
param(False, False, True, id="ignore none"),
],
)
def test_ignore_missing_version(global_value: bool, file_value: bool, should_raise: bool, tmp_path: Path) -> None:
"""If the version is not found in the file, do nothing."""
# Arrange
version_path = tmp_path / Path("VERSION")
version_path.write_text("1.2.3")

overrides = {
"current_version": "1.2.5",
"ignore_missing_version": True,
"files": [{"filename": str(version_path)}],
"ignore_missing_version": global_value,
"files": [{"filename": str(version_path), "ignore_missing_version": file_value}],
}
conf, version_config, current_version = get_config_data(overrides)
assert conf.ignore_missing_version is True
new_version = current_version.bump("patch", version_config.order)
cfg_files = [files.ConfiguredFile(file_cfg, version_config) for file_cfg in conf.files]

# Act
files.modify_files(cfg_files, current_version, new_version, get_context(conf))
with inside_dir(tmp_path):
conf, version_config, current_version = get_config_data(overrides)
new_version = current_version.bump("patch", version_config.order)
cfg_files = [files.ConfiguredFile(file_cfg, version_config) for file_cfg in conf.files]

# Act
if should_raise:
with pytest.raises(VersionNotFoundError):
files.modify_files(cfg_files, current_version, new_version, get_context(conf))
else:
files.modify_files(cfg_files, current_version, new_version, get_context(conf))

# Assert
assert version_path.read_text() == "1.2.3"
Expand Down

0 comments on commit c1ef3b2

Please sign in to comment.