def test_tag_sort_by_tag_date(repo, create_config, message):
    sort_by = "taggerdate"
    create_config(repo, {"sort_by": sort_by})

    commits = {}
    tags_to_commit = [
        "1.1.10",
        "1.1.0",
        "1.1.1",
    ]

    for i, tag in enumerate(tags_to_commit):
        create_file(repo, commit=False)
        dt = datetime.now() - timedelta(days=len(tags_to_commit) - i)
        create_commit(repo, "Some commit", dt=dt)
        commits[tag] = get_sha(repo)

    tags_to_create = [
        "1.1.0",
        "1.1.1",
        "1.1.10",
    ]

    for tag in tags_to_create:
        create_tag(repo, tag, message=message, commit=commits[tag])
        time.sleep(1)

    if message:
        # the result is not stable because latest tag (by creation time)
        # has nothing in common with commit creation time
        assert "1.1.10" in get_version(repo)
    else:
        assert get_version(repo).startswith("1.1")
def test_tag_sort_by_commit_date(repo, create_config, message):
    sort_by = "committerdate"
    create_config(repo, {"sort_by": sort_by})

    commits = {}
    tags_to_commit = [
        "1.1.10",
        "1.1.0",
        "1.1.1",
    ]

    for i, tag in enumerate(tags_to_commit):
        create_file(repo, commit=False)
        dt = datetime.now() - timedelta(days=len(tags_to_commit) - i)
        create_commit(repo, "Some commit", dt=dt)
        commits[tag] = get_sha(repo)
        time.sleep(1)

    tags_to_create = [
        "1.1.0",
        "1.1.1",
        "1.1.10",
    ]

    for tag in tags_to_create:
        create_tag(repo, tag, message=message, commit=commits[tag])

    if not message:
        assert get_version(repo) == "1.1.1"
    else:
        assert get_version(repo).startswith("1.1")
def test_tag_sort_by_version(repo, create_config, message):
    sort_by = "version:refname"
    create_config(repo, {"sort_by": sort_by})

    commits = {}

    tags_to_commit = [
        "1.1.0",
        "1.1.10",
        "1.1.1",
    ]

    for i, tag in enumerate(tags_to_commit):
        create_file(repo, commit=False)
        dt = datetime.now() - timedelta(days=len(tags_to_commit) - i)
        create_commit(repo, "Some commit", dt=dt)
        commits[tag] = get_sha(repo)

    tags_to_create = [
        "1.1.0",
        "1.1.10",
        "1.1.1",
    ]

    for tag in tags_to_create:
        create_tag(repo, tag, message=message, commit=commits[tag])

    # the result is not stable because latest tag (by name)
    # has nothing in common with commit creation time
    # so it could mess everything up: https://github.com/dolfinus/setuptools-git-versioning/issues/22
    # that's why this value is not default
    assert "1.1.10" in get_version(repo)
def test_tag_sort_by_create_date(repo, create_config, message, sort_by):
    if sort_by:
        create_config(repo, {"sort_by": sort_by})
    else:
        create_config(repo)

    commits = {}
    tags_to_commit = [
        "1.1.0",
        "1.1.10",
        "1.1.1",
    ]

    for i, tag in enumerate(tags_to_commit):
        create_file(repo, commit=False)
        dt = datetime.now() - timedelta(days=len(tags_to_commit) - i)
        create_commit(repo, "Some commit", dt=dt)
        commits[tag] = get_sha(repo)
        time.sleep(1)

    tags_to_create = [
        "1.1.10",
        "1.1.1",
        "1.1.0",
    ]

    for tag in tags_to_create:
        create_tag(repo, tag, message=message, commit=commits[tag])
        time.sleep(1)

    if message:
        # the result is not stable because latest tag (by creation time)
        # has nothing in common with commit creation time
        # so it is not recommended to create annotated tags in the past
        assert "1.1.0" in get_version(repo)
    else:
        # but at least creatordate field is present in both tag types
        # https://stackoverflow.com/questions/67206124
        # so this is a default value
        assert get_version(repo) == "1.1.1"
示例#5
0
def test_version_file(repo, create_config, template):
    config = {
        "version_file": "VERSION.txt",
    }
    if template:
        # template is ignored
        config["dev_template"] = template

    create_config(repo, config)

    create_file(repo, "VERSION.txt", "1.0.0")
    assert get_version(repo) == "1.0.0"

    create_file(repo)
    assert get_version(repo) == "1.0.0"

    create_file(repo, add=True, commit=False)
    assert get_version(repo) == "1.0.0"
    create_commit(repo, "add file")

    create_file(repo, add=False)
    assert get_version(repo) == "1.0.0"
示例#6
0
def test_version_file_dirty(repo, create_config, add, template, subst):
    config = {
        "version_file": "VERSION.txt",
        "count_commits_from_version_file": True,
    }
    if template:
        # template is not ignored
        config["dirty_template"] = template

    create_config(repo, config)

    create_file(repo, "VERSION.txt", "1.0.0")
    create_file(repo, commit=False)

    full_sha = get_full_sha(repo)
    sha = get_sha(repo)
    assert get_version(repo) == subst.format(sha=sha, full_sha=full_sha, ccount=0)

    create_commit(repo, "add file")
    create_file(repo, add=False)

    full_sha = get_full_sha(repo)
    sha = get_sha(repo)
    assert get_version(repo) == subst.format(sha=sha, full_sha=full_sha, ccount=1)