1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
"""Tests for the conventional commit convention."""
from __future__ import annotations
from git_changelog import Commit, ConventionalCommitConvention
def test_conventional_convention_breaking_change() -> None:
"""Breaking change (singular) is correctly identified."""
subject = "feat: this is a new breaking feature"
body = ["BREAKING CHANGE: there is a breaking feature in this code"]
commit = Commit(
commit_hash="aaaaaaa",
subject=subject,
body=body,
author_date="1574340645",
committer_date="1574340645",
)
convention = ConventionalCommitConvention()
commit_dict = convention.parse_commit(commit)
assert commit_dict["type"] == "Features"
assert commit_dict["scope"] is None
assert commit_dict["is_major"]
assert not commit_dict["is_minor"]
assert not commit_dict["is_patch"]
def test_conventional_convention_breaking_changes() -> None:
"""Breaking changes (plural) are correctly identified."""
subject = "feat: this is a new breaking feature"
body = ["BREAKING CHANGES: there is a breaking feature in this code"]
commit = Commit(
commit_hash="aaaaaaa",
subject=subject,
body=body,
author_date="1574340645",
committer_date="1574340645",
)
convention = ConventionalCommitConvention()
commit_dict = convention.parse_commit(commit)
assert commit_dict["type"] == "Features"
assert commit_dict["scope"] is None
assert commit_dict["is_major"]
assert not commit_dict["is_minor"]
assert not commit_dict["is_patch"]
def test_conventional_convention_subject_breaking_change() -> None:
"""Breaking change in the subject (!) are correctly identified."""
subject = "feat!: this is a new breaking feature"
body = ["There is a breaking feature in this code"]
commit = Commit(
commit_hash="aaaaaaa",
subject=subject,
body=body,
author_date="1574340645",
committer_date="1574340645",
)
convention = ConventionalCommitConvention()
commit_dict = convention.parse_commit(commit)
assert commit_dict["type"] == "Features"
assert commit_dict["scope"] is None
assert commit_dict["is_major"]
assert not commit_dict["is_minor"]
assert not commit_dict["is_patch"]
def test_conventional_convention_subject_breaking_change_with_scope() -> None:
"""Breaking change in the subject (!) with scope are correctly identified."""
subject = "feat(scope)!: this is a new breaking feature"
body = ["There is a breaking feature in this code"]
commit = Commit(
commit_hash="aaaaaaa",
subject=subject,
body=body,
author_date="1574340645",
committer_date="1574340645",
)
convention = ConventionalCommitConvention()
commit_dict = convention.parse_commit(commit)
assert commit_dict["type"] == "Features"
assert commit_dict["scope"] == "scope"
assert commit_dict["is_major"]
assert not commit_dict["is_minor"]
assert not commit_dict["is_patch"]
def test_conventional_convention_feat() -> None:
"""Feature commit is correctly identified."""
subject = "feat: this is a new feature"
commit = Commit(
commit_hash="aaaaaaa",
subject=subject,
author_date="1574340645",
committer_date="1574340645",
)
convention = ConventionalCommitConvention()
commit_dict = convention.parse_commit(commit)
assert commit_dict["type"] == "Features"
assert commit_dict["scope"] is None
assert not commit_dict["is_major"]
assert commit_dict["is_minor"]
assert not commit_dict["is_patch"]
def test_conventional_convention_feat_with_scope() -> None:
"""Feature commit is correctly identified."""
subject = "feat(scope): this is a new feature"
commit = Commit(
commit_hash="aaaaaaa",
subject=subject,
author_date="1574340645",
committer_date="1574340645",
)
convention = ConventionalCommitConvention()
commit_dict = convention.parse_commit(commit)
assert commit_dict["type"] == "Features"
assert commit_dict["scope"] == "scope"
assert not commit_dict["is_major"]
assert commit_dict["is_minor"]
assert not commit_dict["is_patch"]
def test_conventional_convention_fix() -> None:
"""Bug fix commit is correctly identified."""
subject = "fix: this is a bug fix"
commit = Commit(
commit_hash="aaaaaaa",
subject=subject,
author_date="1574340645",
committer_date="1574340645",
)
convention = ConventionalCommitConvention()
commit_dict = convention.parse_commit(commit)
assert commit_dict["type"] == "Bug Fixes"
assert commit_dict["scope"] is None
assert not commit_dict["is_major"]
assert not commit_dict["is_minor"]
assert commit_dict["is_patch"]
def test_conventional_convention_fix_with_scope() -> None:
"""Bug fix commit is correctly identified."""
subject = "fix(scope): this is a bug fix"
commit = Commit(
commit_hash="aaaaaaa",
subject=subject,
author_date="1574340645",
committer_date="1574340645",
)
convention = ConventionalCommitConvention()
commit_dict = convention.parse_commit(commit)
assert commit_dict["type"] == "Bug Fixes"
assert commit_dict["scope"] == "scope"
assert not commit_dict["is_major"]
assert not commit_dict["is_minor"]
assert commit_dict["is_patch"]
|