Example #1
0
def guess_initial_version(config: ProjectConfig) -> Version:
    maybe_version_str = find_project_version(config)
    if maybe_version_str:
        return Version.parse(maybe_version_str, config=config)

    if config.version_type == VersionTypeEnum.semver:
        return Version(version=SemVer.initial())
    return Version(version=CalVer.initial(schema=config.version_schema))
def test_semver_update(semver: SemVer, update_config: UpdateConfig,
                       expected: SemVer):
    assert semver.update(update_config) == expected
def test_semver_parse_invalid(invalid_semver):
    with pytest.raises(ValueError):
        SemVer.parse(invalid_semver)
def test_semver_parse(expected: SemVer, semver: str):
    assert SemVer.parse(semver) == expected
def test_semver_initial():
    assert SemVer.initial().format() == "1.0.0"
def test_semver_format(semver: SemVer, expected: str):
    assert semver.format() == expected
import pytest

from badabump.configs import UpdateConfig
from badabump.versions.semver import SemVer

VERSIONS = (
    (SemVer(major=0, minor=0, patch=1), "0.0.1"),
    (SemVer(major=0, minor=1, patch=2), "0.1.2"),
    (SemVer(major=1, minor=0, patch=1), "1.0.1"),
    (SemVer(major=20, minor=10, patch=10), "20.10.10"),
)


@pytest.mark.parametrize("semver, expected", VERSIONS)
def test_semver_format(semver: SemVer, expected: str):
    assert semver.format() == expected


def test_semver_initial():
    assert SemVer.initial().format() == "1.0.0"


@pytest.mark.parametrize("expected, semver", VERSIONS)
def test_semver_parse(expected: SemVer, semver: str):
    assert SemVer.parse(semver) == expected


@pytest.mark.parametrize("invalid_semver", ("1", "1.0", "20201020_10"))
def test_semver_parse_invalid(invalid_semver):
    with pytest.raises(ValueError):
        SemVer.parse(invalid_semver)