-
-
Notifications
You must be signed in to change notification settings - Fork 25
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 #226 from callowayproject/225-show-bump-attributee…
…rror Fix version visualization and add verbose logging
- Loading branch information
Showing
12 changed files
with
140 additions
and
101 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
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
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
This file was deleted.
Oops, something went wrong.
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,79 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
from click import UsageError | ||
|
||
from bumpversion import exceptions | ||
from bumpversion.context import get_context | ||
from bumpversion.versioning.version_config import VersionConfig | ||
from tests.conftest import get_config_data | ||
|
||
|
||
def test_invalid_parse_raises_error(): | ||
"""An invalid parse regex value raises an error.""" | ||
with pytest.raises(exceptions.UsageError): | ||
VersionConfig(r"(.+", ("{major}.{minor}.{patch}",), search="", replace="") | ||
|
||
|
||
class TestParse: | ||
"""Tests for parsing a version.""" | ||
|
||
def test_cant_parse_returns_none(self): | ||
"""The default behavior when unable to parse a string is to return None.""" | ||
# Assemble | ||
overrides = { | ||
"current_version": "19.6.0", | ||
"parse": r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+).*", | ||
"serialize": ["{major}.{minor}.{patch}"], | ||
} | ||
_, version_config, current_version = get_config_data(overrides) | ||
|
||
# Act and Assert | ||
assert version_config.parse("A.B.C") is None | ||
|
||
def test_cant_parse_raises_error_when_set(self): | ||
"""When `raise_error` is enabled, the inability to parse a string will raise an error.""" | ||
# Assemble | ||
overrides = { | ||
"current_version": "19.6.0", | ||
"parse": r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+).*", | ||
"serialize": ["{major}.{minor}.{patch}"], | ||
} | ||
_, version_config, current_version = get_config_data(overrides) | ||
|
||
# Act and Assert | ||
with pytest.raises(exceptions.UsageError): | ||
version_config.parse("A.B.C", raise_error=True) | ||
|
||
|
||
class TestSerialize: | ||
"""Tests for the VersionConfig.serialize() method.""" | ||
|
||
def test_distance_to_latest_tag_in_pattern(self): | ||
"""Using ``distance_to_latest_tag`` in the serialization string outputs correctly.""" | ||
from bumpversion.scm import Git, SCMInfo | ||
|
||
overrides = { | ||
"current_version": "19.6.0", | ||
"parse": r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+).*", | ||
"serialize": ["{major}.{minor}.{patch}-pre{distance_to_latest_tag}"], | ||
} | ||
conf, version_config, current_version = get_config_data(overrides) | ||
conf.scm_info = SCMInfo( | ||
tool=Git, commit_sha="1234123412341234", distance_to_latest_tag=3, current_version="19.6.0", dirty=False | ||
) | ||
assert version_config.serialize(current_version, get_context(conf)) == "19.6.0-pre3" | ||
|
||
def test_environment_var_in_serialize_pattern(self): | ||
"""Environment variables are serialized correctly.""" | ||
import os | ||
|
||
os.environ["BUILD_NUMBER"] = "567" | ||
overrides = { | ||
"current_version": "2.3.4", | ||
"parse": r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+).*", | ||
"serialize": ["{major}.{minor}.{patch}-pre{$BUILD_NUMBER}"], | ||
} | ||
conf, version_config, current_version = get_config_data(overrides) | ||
assert version_config.serialize(current_version, get_context(conf)) == "2.3.4-pre567" | ||
del os.environ["BUILD_NUMBER"] |