Exemplo n.º 1
0
def test_tag_regex1(tag, expected):
    config = Configuration()
    config.tag_regex = r"^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$"
    if "+" in tag:
        # pytest bug wrt cardinality
        with pytest.warns(UserWarning):
            result = meta(tag, config=config)
    else:
        result = meta(tag, config=config)

    assert result.tag.public == expected
Exemplo n.º 2
0
def test_archival_to_version(expected, data):
    config = Configuration()
    version = archival_to_version(data, config=config)
    assert (
        format_version(
            version, version_scheme="guess-next-dev", local_scheme="node-and-date"
        )
        == expected
    )
Exemplo n.º 3
0
def test_tag_regex1(tag, expected):
    config = Configuration()
    if "+" in tag:
        # pytest bug wrt cardinality
        with pytest.warns(UserWarning):
            result = meta(tag, config=config)
    else:
        result = meta(tag, config=config)

    assert result.tag.public == expected
Exemplo n.º 4
0
def test_config_from_pyproject(tmpdir):
    fn = tmpdir / "pyproject.toml"
    fn.write_text(
        textwrap.dedent("""
            [tool.setuptools_scm]
            [project]
            description = "Factory ⸻ A code generator 🏭"
            authors = [{name = "Łukasz Langa"}]
            """),
        encoding="utf-8",
    )
    assert Configuration.from_file(str(fn))
Exemplo n.º 5
0
def myparse(
        root, describe_command=DEFAULT_DESCRIBE, config=None):
    """
    rewriting of setuptools_scm.git.parse method to remove -branch string
    from any tags.  This library is clearly not designed for people to adjust
    its function so I had to lift entire function from Aug 8 master with SHA 
    a91b40c99ea9bfc4289272285f17e1d43c243b76

    """
    if not config:
        config = Configuration(root=root)

    if not has_command("git"):
        return

    wd = GitWorkdir.from_potential_worktree(config.absolute_root)
    if wd is None:
        return

    out, unused_err, ret = wd.do_ex(describe_command)
    if ret:
        # If 'git describe' failed, try to get the information otherwise.
        rev_node = wd.node()
        dirty = wd.is_dirty()

        if rev_node is None:
            return meta("0.0", distance=0, dirty=dirty, config=config)

        return meta(
            "0.0",
            distance=wd.count_all_nodes(),
            node="g" + rev_node,
            dirty=dirty,
            branch=wd.get_branch(),
            config=config,
        )
    else:
        tag, number, node, dirty = _git_parse_describe(out)
        branch = wd.get_branch()
        if number:
            return meta(
                tag.replace('-branch',''),
                config=config,
                distance=number,
                node=node,
                dirty=dirty,
                branch=branch,
            )
        else:
            return meta(tag.replace('-branch', ''), config=config, node=node, dirty=dirty, branch=branch)
Exemplo n.º 6
0
def test_custom_version_cls():
    """Test that we can pass our own version class instead of pkg_resources"""
    class MyVersion:
        def __init__(self, tag_str: str):
            self.tag = tag_str

        def __repr__(self):
            return "Custom %s" % self.tag

    scm_version = meta("1.0.0-foo",
                       config=Configuration(version_cls=MyVersion))

    assert isinstance(scm_version.tag, MyVersion)
    assert repr(scm_version.tag) == "Custom 1.0.0-foo"
Exemplo n.º 7
0
import pytest
from setuptools_scm.config import Configuration
from setuptools_scm.version import (
    meta,
    simplified_semver_version,
    release_branch_semver_version,
    tags_to_versions,
    no_guess_dev_version,
    guess_next_version,
)

c = Configuration()


@pytest.mark.parametrize(
    "version, expected_next",
    [
        pytest.param(meta("1.0.0", config=c), "1.0.0", id="exact"),
        pytest.param(meta("1.0", config=c), "1.0.0", id="short_tag"),
        pytest.param(
            meta("1.0.0", distance=2, branch="default", config=c),
            "1.0.1.dev2",
            id="normal_branch",
        ),
        pytest.param(
            meta("1.0", distance=2, branch="default", config=c),
            "1.0.1.dev2",
            id="normal_branch_short_tag",
        ),
        pytest.param(
            meta("1.0.0", distance=2, branch="feature", config=c),
Exemplo n.º 8
0
def test_config_from_pyproject(tmpdir):
    fn = tmpdir / "pyproject.toml"
    fn.write_text("[tool.setuptools_scm]\n", encoding="utf-8")
    assert Configuration.from_file(str(fn))
Exemplo n.º 9
0
def test_tag_regex(tag, expected_version):
    config = Configuration()
    match = config.tag_regex.match(tag)
    version = match.group("version")
    assert version == expected_version
Exemplo n.º 10
0
def test_tags_to_versions():
    config = Configuration()
    versions = tags_to_versions(["1", "2", "3"], config=config)
    assert isinstance(versions, list)  # enable subscription
Exemplo n.º 11
0
def test_tag_regex1(tag, expected):
    Configuration(
    ).tag_regex = r"^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$"
    result = meta(tag)
    assert result.tag.public == expected
Exemplo n.º 12
0
def test_config_regex_init():
    tag_regex = re.compile(r"v(\d+)")
    conf = Configuration(tag_regex=tag_regex)
    assert conf.tag_regex is tag_regex