def from_parts( cls, major: int, minor: Optional[int] = None, patch: Optional[int] = None, extra: Optional[Union[int, Tuple[int, ...]]] = None, pre: Optional[ReleaseTag] = None, post: Optional[ReleaseTag] = None, dev: Optional[ReleaseTag] = None, local: "LocalSegmentType" = None, ): return cls( release=Release(major=major, minor=minor, patch=patch, extra=extra), pre=pre, post=post, dev=dev, local=local, )
def from_parts( cls, major: int, minor: int | None = None, patch: int | None = None, extra: int | tuple[int, ...] | None = None, pre: ReleaseTag | None = None, post: ReleaseTag | None = None, dev: ReleaseTag | None = None, local: LocalSegmentType = None, *, epoch: int = 0, ) -> Version: return cls( release=Release(major=major, minor=minor, patch=patch, extra=extra), pre=pre, post=post, dev=dev, local=local, epoch=epoch, )
def _get_release(cls, match: Optional[Match[AnyStr]]) -> Release: if not match or match.group("release") is None: return Release(0) return Release.from_parts( *(int(i) for i in match.group("release").split(".")))
def test_pep440_release_segment_from_parts(parts, result): assert Release.from_parts(*parts) == result
import pytest from poetry.core.version.exceptions import InvalidVersion from poetry.core.version.pep440 import PEP440Version from poetry.core.version.pep440 import Release from poetry.core.version.pep440 import ReleaseTag from poetry.core.version.pep440.segments import RELEASE_PHASES from poetry.core.version.pep440.segments import RELEASE_PHASES_SHORT @pytest.mark.parametrize( "parts,result", [ ((1,), Release(1)), ((1, 2), Release(1, 2)), ((1, 2, 3), Release(1, 2, 3)), ((1, 2, 3, 4), Release(1, 2, 3, 4)), ((1, 2, 3, 4, 5, 6), Release(1, 2, 3, (4, 5, 6))), ], ) def test_pep440_release_segment_from_parts(parts, result): assert Release.from_parts(*parts) == result @pytest.mark.parametrize( "parts,result", [ (("a",), ReleaseTag("alpha", 0)), (("a", 1), ReleaseTag("alpha", 1)), (("b",), ReleaseTag("beta", 0)), (("b", 1), ReleaseTag("beta", 1)),
def test_pep440_release_segment_from_parts( parts: tuple[int, ...], result: Release ) -> None: assert Release.from_parts(*parts) == result
def _get_release(cls, match: Match[str] | None) -> Release: if not match or match.group("release") is None: return Release(0) return Release.from_parts(*(int(i) for i in match.group("release").split(".")))