-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from callowayproject/70-version-less-search-r…
…eplace-raise-keyerror-new_version-exception Fixes Key Error exception when searching
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""Tests for the ConfiguredFile class.""" | ||
from bumpversion.files import ConfiguredFile, FileChange | ||
from bumpversion.version_part import VersionConfig | ||
|
||
|
||
class TestConfiguredFile: | ||
"""Tests for the ConfiguredFile class.""" | ||
|
||
class TestClassCreation: | ||
"""Tests for the creation of the ConfiguredFile class.""" | ||
|
||
def test_file_change_is_identical_to_input(self): | ||
"""Test that the file change is identical to the input, but not the same object.""" | ||
change = FileChange( | ||
filename="boobar.txt", | ||
search="dashes: {current_version}", | ||
replace="dashes: {new_version}", | ||
parse=r"(?P<major>\d+)-(?P<minor>\d+)-(?P<patch>\d+)", | ||
serialize=("{major}-{minor}-{patch}",), | ||
regex=True, | ||
ignore_missing_version=False, | ||
) | ||
version_config = VersionConfig( | ||
parse="(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?", | ||
serialize=("{major}.{minor}.{patch}",), | ||
search="{current_version}", | ||
replace="{new_version}", | ||
) | ||
cfg_file = ConfiguredFile(change, version_config) | ||
assert cfg_file.file_change == change | ||
assert cfg_file.file_change is not change | ||
|
||
def test_version_config_uses_file_change_attrs(self): | ||
"""Test that the version config uses the file change attributes, and the original part configs.""" | ||
change = FileChange( | ||
filename="boobar.txt", | ||
search="dashes: {current_version}", | ||
replace="dashes: {new_version}", | ||
parse=r"(?P<major>\d+)-(?P<minor>\d+)-(?P<patch>\d+)", | ||
serialize=("{major}-{minor}-{patch}",), | ||
regex=True, | ||
ignore_missing_version=False, | ||
) | ||
version_config = VersionConfig( | ||
parse="(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?", | ||
serialize=("{major}.{minor}.{patch}",), | ||
search="{current_version}", | ||
replace="{new_version}", | ||
) | ||
expected = VersionConfig( | ||
parse=change.parse, | ||
search=change.search, | ||
replace=change.replace, | ||
serialize=change.serialize, | ||
part_configs=version_config.part_configs, | ||
) | ||
cfg_file = ConfiguredFile(change, version_config) | ||
assert cfg_file.version_config == expected |