Skip to content

Commit c522c75

Browse files
committed
Fixed the rendering of numeric version components.
- Numeric version components now will attempt to render its value as an integer and fall back to the parsed value.
1 parent c3d89a3 commit c522c75

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

bumpversion/versioning/models.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ def __init__(
216216
self.components = components
217217
self.original = original
218218

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

223223
def __getitem__(self, key: str) -> VersionComponent:
224224
return self.components[key]

tests/test_versioning/test_serialization.py

+10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def test_parse_pattern_with_newlines(self):
6868
pattern = r"MAJOR=(?P<major>\d+)\nMINOR=(?P<minor>\d+)\nPATCH=(?P<patch>\d+)\n"
6969
assert parse_version("MAJOR=31\nMINOR=0\nPATCH=3\n", pattern) == {"major": "31", "minor": "0", "patch": "3"}
7070

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

7277
class TestSerialize:
7378
"""Test the serialize function."""
@@ -196,6 +201,11 @@ def test_with_additional_context(self):
196201
== "1.2.3+build.1"
197202
)
198203

204+
def test_zero_padding(self):
205+
"""A numeric component with zero-padding notation should be rendered correctly."""
206+
version = semver_spec().create_version({"major": "1", "minor": "2", "patch": "3"})
207+
assert serialize(version, serialize_patterns=["{major}.{minor:02}.{patch}"], context={}) == "1.02.3"
208+
199209
class TestRaisesError:
200210
def test_if_context_is_missing_values(self):
201211
"""An error is raised if not all parts required in the format have values."""

0 commit comments

Comments
 (0)