How to use the dunamai.Version.from_any_vcs function in dunamai

To help you get started, we’ve selected a few dunamai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mtkennerly / dunamai / tests / unit / test_dunamai.py View on Github external
return out

    return inner


def make_from_callback(function: Callable, mock_commit: Optional[str] = "abc") -> Callable:
    def inner(*args, **kwargs):
        version = function(*args, **kwargs)
        if version.commit and mock_commit:
            version.commit = mock_commit
        return version

    return inner


from_any_vcs = make_from_callback(Version.from_any_vcs)
from_any_vcs_unmocked = make_from_callback(Version.from_any_vcs, mock_commit=None)
from_explicit_vcs = make_from_callback(Version.from_vcs)


def test__version__init() -> None:
    v = Version("1", stage=("a", 2), distance=3, commit="abc", dirty=True)
    assert v.base == "1"
    assert v.stage == "a"
    assert v.revision == 2
    assert v.distance == 3
    assert v.commit == "abc"
    assert v.dirty


def test__version__str() -> None:
    v = Version("1", stage=("a", 2), distance=3, commit="abc", dirty=True)
github mtkennerly / dunamai / tests / integration / test_dunamai.py View on Github external
return out

    return inner


def make_from_callback(function: Callable, mock_commit: Optional[str] = "abc") -> Callable:
    def inner(*args, **kwargs):
        version = function(*args, **kwargs)
        if version.commit and mock_commit:
            version.commit = mock_commit
        return version

    return inner


from_any_vcs = make_from_callback(Version.from_any_vcs)
from_any_vcs_unmocked = make_from_callback(Version.from_any_vcs, mock_commit=None)
from_explicit_vcs = make_from_callback(Version.from_vcs)


@pytest.mark.skipif(shutil.which("git") is None, reason="Requires Git")
def test__version__from_git(tmp_path) -> None:
    vcs = tmp_path / "dunamai-git"
    vcs.mkdir()
    run = make_run_callback(vcs)
    from_vcs = make_from_callback(Version.from_git)

    with chdir(vcs):
        run("git init")
        assert from_vcs() == Version("0.0.0", distance=0, commit=None, dirty=True)

        (vcs / "foo.txt").write_text("hi")
github mtkennerly / dunamai / tests / unit / test_dunamai.py View on Github external
def test__version__from_any_vcs(tmp_path) -> None:
    with chdir(tmp_path):
        with pytest.raises(RuntimeError):
            Version.from_any_vcs()
        with pytest.raises(RuntimeError):
            Version.from_vcs(Vcs.Any)