Skip to content

Commit

Permalink
Fixed the rendering of numeric version components.
Browse files Browse the repository at this point in the history
- Numeric version components now will attempt to render its value as an integer and fall back to the parsed value.
  • Loading branch information
coordt committed Apr 23, 2024
1 parent c3d89a3 commit c522c75
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bumpversion/versioning/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ def __init__(
self.components = components
self.original = original

def values(self) -> Dict[str, str]:
def values(self) -> Dict[str, VersionComponent]:
"""Return the values of the parts."""
return {key: value.value for key, value in self.components.items()}
return dict(self.components.items())

def __getitem__(self, key: str) -> VersionComponent:
return self.components[key]
Expand Down
10 changes: 10 additions & 0 deletions tests/test_versioning/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def test_parse_pattern_with_newlines(self):
pattern = r"MAJOR=(?P<major>\d+)\nMINOR=(?P<minor>\d+)\nPATCH=(?P<patch>\d+)\n"
assert parse_version("MAJOR=31\nMINOR=0\nPATCH=3\n", pattern) == {"major": "31", "minor": "0", "patch": "3"}

def test_parse_pattern_with_zero_padding(self):
"""A parse pattern with zero padding should be parsed correctly."""
pattern = r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)"
assert parse_version("5.06.0", pattern) == {"major": "5", "minor": "06", "patch": "0"}


class TestSerialize:
"""Test the serialize function."""
Expand Down Expand Up @@ -196,6 +201,11 @@ def test_with_additional_context(self):
== "1.2.3+build.1"
)

def test_zero_padding(self):
"""A numeric component with zero-padding notation should be rendered correctly."""
version = semver_spec().create_version({"major": "1", "minor": "2", "patch": "3"})
assert serialize(version, serialize_patterns=["{major}.{minor:02}.{patch}"], context={}) == "1.02.3"

class TestRaisesError:
def test_if_context_is_missing_values(self):
"""An error is raised if not all parts required in the format have values."""
Expand Down

0 comments on commit c522c75

Please sign in to comment.