Skip to content

Commit 74ffbcb

Browse files
committed
Fix version string formatting in Version class and update related tests
1 parent 09f50cf commit 74ffbcb

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

version/tests/version_tests.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,11 @@ def test_is_valid_string(version_str, expected):
553553
(1, 0, 0, "rc.1", None, "1.0.0.rc_1"),
554554
(1, 2, 3, "alpha.1", None, "1.2.3.alpha_1"),
555555
(1, 2, 3, "beta.2.3", None, "1.2.3.beta_2_3"),
556-
(1, 0, 0, None, "build", "1.0.0.postbuild"),
557-
(1, 0, 0, None, "build.123", "1.0.0.postbuild_123"),
558-
(1, 2, 3, "alpha", "build", "1.2.3.alpha.postbuild"),
559-
(1, 2, 3, "alpha.1", "build.123", "1.2.3.alpha_1.postbuild_123"),
560-
(10, 20, 30, "beta.1.2.3", "build.456.789", "10.20.30.beta_1_2_3.postbuild_456_789"),
556+
(1, 0, 0, None, "build", "1.0.0.build"),
557+
(1, 0, 0, None, "build.123", "1.0.0.build_123"),
558+
(1, 2, 3, "alpha", "build", "1.2.3.alpha.build"),
559+
(1, 2, 3, "alpha.1", "build.123", "1.2.3.alpha_1.build_123"),
560+
(10, 20, 30, "beta.1.2.3", "build.456.789", "10.20.30.beta_1_2_3.build_456_789"),
561561
],
562562
ids=[
563563
"no_prerelease_no_metadata",
@@ -582,14 +582,14 @@ def test_to_python_version_replaces_special_chars():
582582
# Test that dots and dashes are replaced with underscores
583583
version = Version(1, 2, 3, "alpha.beta", "metadata.123")
584584
result = version.to_python_version()
585-
assert result == "1.2.3.alpha_beta.postmetadata_123"
585+
assert result == "1.2.3.alpha_beta.metadata_123"
586586
assert '.' not in result.split('.')[-1] # No dots in the last segment after splitting on main dots
587587

588588
def test_to_python_version_vs_str():
589589
# Verify that to_python_version and __str__ produce different outputs for versions with prerelease/metadata
590590
version = Version(1, 2, 3, "alpha.1", "build.123")
591591
python_version = version.to_python_version()
592592
semver_version = str(version)
593-
assert python_version == "1.2.3.alpha_1.postbuild_123"
593+
assert python_version == "1.2.3.alpha_1.build_123"
594594
assert semver_version == "1.2.3-alpha.1+build.123"
595595
assert python_version != semver_version

version/version/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def to_python_version(self) -> str:
179179
version_str += f".{prerelease}"
180180
if self.__metadata:
181181
metadata = self.__metadata.replace('.', '_').replace('-', '_')
182-
version_str += f".post{metadata}"
182+
version_str += f".{metadata}"
183183
return version_str
184184

185185
def __repr__(self) -> str:

0 commit comments

Comments
 (0)