How to use the dunamai.Version 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 / integration / test_dunamai.py View on Github external
def test__version__from_darcs(tmp_path) -> None:
    vcs = tmp_path / "dunamai-darcs"
    vcs.mkdir()
    run = make_run_callback(vcs)
    from_vcs = make_from_callback(Version.from_darcs)

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

        (vcs / "foo.txt").write_text("hi")
        assert from_vcs() == Version("0.0.0", distance=0, commit=None, dirty=True)

        run("darcs add foo.txt")
        run('darcs record -am "Initial commit"')
        assert from_vcs() == Version("0.0.0", distance=1, commit="abc", dirty=False)

        run("darcs tag v0.1.0")
        assert from_vcs() == Version("0.1.0", commit="abc", dirty=False)
        assert from_vcs(latest_tag=True) == Version("0.1.0", commit="abc", dirty=False)
        assert run("dunamai from darcs") == "0.1.0"
        assert run("dunamai from any") == "0.1.0"

        (vcs / "foo.txt").write_text("bye")
        assert from_vcs() == Version("0.1.0", commit="abc", dirty=True)
github mtkennerly / dunamai / tests / integration / test_dunamai.py View on Github external
assert run("dunamai from any") == "0.1.0"

        (vcs / "foo.txt").write_text("bye")
        assert from_vcs() == Version("0.1.0", commit="abc", dirty=True)

        run('darcs record -am "Second"')
        assert from_vcs() == Version("0.1.0", distance=1, commit="abc", dirty=False)
        assert from_any_vcs() == Version("0.1.0", distance=1, commit="abc", dirty=False)

        run("darcs tag unmatched")
        assert from_vcs() == Version("0.1.0", distance=2, commit="abc", dirty=False)
        with pytest.raises(ValueError):
            from_vcs(latest_tag=True)

        run("darcs tag v0.2.0")
        assert from_vcs() == Version("0.2.0", commit="abc", dirty=False)

        run("darcs obliterate --all --last 3")
        assert from_vcs() == Version("0.1.0", commit="abc", dirty=False)
github mtkennerly / dunamai / tests / unit / test_dunamai.py View on Github external
def test__version__serialize__pvp_with_metadata() -> None:
    style = Style.Pvp
    assert Version("0.1.0").serialize(style=style) == "0.1.0"
    assert Version("0.1.0").serialize(metadata=True, style=style) == "0.1.0"
    assert Version("0.1.0").serialize(metadata=False, style=style) == "0.1.0"

    assert Version("0.1.0", stage=("a", 1), commit="abc").serialize(style=style) == "0.1.0-a-1"
    assert (
        Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=True, style=style)
        == "0.1.0-a-1-abc"
    )
    assert (
        Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=False, style=style)
        == "0.1.0-a-1"
    )

    assert Version("0.1.0", distance=1, commit="abc").serialize(style=style) == "0.1.0-post-1-abc"
    assert (
        Version("0.1.0", distance=1, commit="abc").serialize(metadata=True, style=style)
        == "0.1.0-post-1-abc"
    )
github mtkennerly / dunamai / tests / unit / test_dunamai.py View on Github external
def test__version__repr() -> None:
    v = Version("1", stage=("a", 2), distance=3, commit="abc", dirty=True)
    assert repr(v) == (
        "Version(base='1', stage='a', revision=2, distance=3, commit='abc', dirty=True)"
    )
github mtkennerly / dunamai / tests / unit / test_dunamai.py View on Github external
== "0.1.0-alpha.2.post.3+abc"
    )
    assert (
        Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize(
            dirty=True, style=style
        )
        == "0.1.0-alpha.2.post.3+abc.dirty"
    )
    assert (
        Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize(
            metadata=False, style=style
        )
        == "0.1.0-alpha.2.post.3"
    )
    assert (
        Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize(
            metadata=False, dirty=True, style=style
        )
        == "0.1.0-alpha.2.post.3"
    )

    assert (
        Version("0.1.0", stage=("alpha", 0), distance=3, commit="abc", dirty=False).serialize(
            style=style
        )
        == "0.1.0-alpha.0.post.3+abc"
    )
    assert (
        Version("0.1.0", stage=("alpha", 2), distance=0, commit="abc", dirty=False).serialize(
            style=style
        )
        == "0.1.0-alpha.2"
github mtkennerly / dunamai / tests / unit / test_dunamai.py View on Github external
assert (
        Version("0.1.0", stage=("alpha", 2), distance=0, commit="abc", dirty=False).serialize(
            style=style
        )
        == "0.1.0-alpha.2"
    )
    assert (
        Version("0.1.0", stage=("alpha", 2), distance=3, commit="000", dirty=False).serialize(
            style=style
        )
        == "0.1.0-alpha.2.post.3+000"
    )

    assert Version("0.1.0", stage=("alpha", None)).serialize(style=style) == "0.1.0-alpha"
    assert Version("0.1.0", stage=("beta", 2)).serialize(style=style) == "0.1.0-beta.2"
    assert Version("0.1.0", stage=("rc", 2)).serialize(style=style) == "0.1.0-rc.2"
github mtkennerly / dunamai / tests / unit / test_dunamai.py View on Github external
def test__version__serialize__pvp_with_metadata() -> None:
    style = Style.Pvp
    assert Version("0.1.0").serialize(style=style) == "0.1.0"
    assert Version("0.1.0").serialize(metadata=True, style=style) == "0.1.0"
    assert Version("0.1.0").serialize(metadata=False, style=style) == "0.1.0"

    assert Version("0.1.0", stage=("a", 1), commit="abc").serialize(style=style) == "0.1.0-a-1"
    assert (
        Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=True, style=style)
        == "0.1.0-a-1-abc"
    )
    assert (
        Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=False, style=style)
        == "0.1.0-a-1"
    )

    assert Version("0.1.0", distance=1, commit="abc").serialize(style=style) == "0.1.0-post-1-abc"
    assert (
        Version("0.1.0", distance=1, commit="abc").serialize(metadata=True, style=style)
        == "0.1.0-post-1-abc"
    )
    assert (
        Version("0.1.0", distance=1, commit="abc").serialize(metadata=False, style=style)
        == "0.1.0-post-1"
    )
github mtkennerly / dunamai / tests / unit / test_dunamai.py View on Github external
def test__version__ordering() -> None:
    assert Version("0.1.0", distance=2) == Version("0.1.0", distance=2)
    assert Version("0.2.0") > Version("0.1.0")
    assert Version("0.1.0", distance=2) > Version("0.1.0", distance=1)
    with pytest.raises(TypeError):
        Version("0.1.0") == "0.1.0"
    with pytest.raises(TypeError):
        Version("0.1.0") < "0.2.0"
    assert Version("0.1.0", commit="a") != Version("0.1.0", commit="b")
    assert Version("0.1.0", dirty=True) == Version("0.1.0", dirty=True)
    assert Version("0.1.0", dirty=False) != Version("0.1.0", dirty=True)
    assert Version("0.1.0") != Version("0.1.0", dirty=True)
    assert Version("0.1.0") != Version("0.1.0", dirty=False)