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_linear_history(repo, create_config): create_tag(repo, "1.0.0") checkout_branch(repo, "dev") create_config(repo) sha = get_sha(repo) assert get_version(repo) == "1.0.0.post1+git.{sha}".format(sha=sha)
def test_tag(repo, create_config, template, subst): if template: create_config(repo, {"template": template}) else: create_config(repo) create_tag(repo, "1.0.0") full_sha = get_full_sha(repo) sha = get_sha(repo) assert get_version(repo) == subst.format(sha=sha, full_sha=full_sha)
def test_tag_dirty(repo, create_config, add, template, subst): if template: create_config(repo, {"dirty_template": template}) else: create_config(repo) create_tag(repo, "1.0.0") create_file(repo, add=add, commit=False) full_sha = get_full_sha(repo) sha = get_sha(repo) assert get_version(repo) == subst.format(sha=sha, full_sha=full_sha)
def test_version_file_count_commits(repo, create_config, template, subst): config = { "version_file": "VERSION.txt", "count_commits_from_version_file": True, } if template: # template is not ignored config["dev_template"] = template create_config(repo, config) create_file(repo, "VERSION.txt", "1.0.0") 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_file(repo) full_sha = get_full_sha(repo) sha = get_sha(repo) assert get_version(repo) == subst.format(sha=sha, full_sha=full_sha, ccount=1)
def test_version_file_tag_is_preferred(repo, create_config): create_tag(repo, "1.2.3") create_file(repo, "VERSION.txt", "1.0.0") create_config( repo, { "version_file": "VERSION.txt", "count_commits_from_version_file": True, }, ) sha = get_sha(repo) assert get_version(repo) == "1.2.3.post2+git.{sha}".format(sha=sha)
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"