|
1 | 1 | import pytest
|
2 | 2 |
|
3 |
| -from commitizen.bump_rule import DefaultBumpRule |
| 3 | +from commitizen.bump_rule import DefaultBumpRule, find_increment_by_callable |
4 | 4 | from commitizen.defaults import MAJOR, MINOR, PATCH
|
5 | 5 |
|
6 | 6 |
|
@@ -93,3 +93,75 @@ def test_other_commit_types(self, bump_rule):
|
93 | 93 | assert bump_rule.get_increment("test: add unit tests", False) is None
|
94 | 94 | assert bump_rule.get_increment("build: update build config", False) is None
|
95 | 95 | assert bump_rule.get_increment("ci: update CI pipeline", False) is None
|
| 96 | + |
| 97 | + |
| 98 | +class TestFindIncrementByCallable: |
| 99 | + @pytest.fixture |
| 100 | + def get_increment(self, bump_rule): |
| 101 | + return lambda x: bump_rule.get_increment(x, False) |
| 102 | + |
| 103 | + def test_single_commit(self, get_increment): |
| 104 | + commit_messages = ["feat: add new feature"] |
| 105 | + assert find_increment_by_callable(commit_messages, get_increment) == MINOR |
| 106 | + |
| 107 | + def test_multiple_commits(self, get_increment): |
| 108 | + commit_messages = [ |
| 109 | + "feat: new feature", |
| 110 | + "fix: bug fix", |
| 111 | + "docs: update readme", |
| 112 | + ] |
| 113 | + assert find_increment_by_callable(commit_messages, get_increment) == MINOR |
| 114 | + |
| 115 | + def test_breaking_change(self, get_increment): |
| 116 | + commit_messages = [ |
| 117 | + "feat: new feature", |
| 118 | + "feat!: breaking change", |
| 119 | + ] |
| 120 | + assert find_increment_by_callable(commit_messages, get_increment) == MINOR |
| 121 | + |
| 122 | + def test_multi_line_commit(self, get_increment): |
| 123 | + commit_messages = [ |
| 124 | + "feat: new feature\n\nBREAKING CHANGE: major change", |
| 125 | + ] |
| 126 | + assert find_increment_by_callable(commit_messages, get_increment) == MINOR |
| 127 | + |
| 128 | + def test_no_increment_needed(self, get_increment): |
| 129 | + commit_messages = [ |
| 130 | + "docs: update documentation", |
| 131 | + "style: format code", |
| 132 | + ] |
| 133 | + assert find_increment_by_callable(commit_messages, get_increment) is None |
| 134 | + |
| 135 | + def test_empty_commits(self, get_increment): |
| 136 | + commit_messages = [] |
| 137 | + assert find_increment_by_callable(commit_messages, get_increment) is None |
| 138 | + |
| 139 | + def test_major_version_zero(self): |
| 140 | + bump_rule = DefaultBumpRule() |
| 141 | + |
| 142 | + commit_messages = [ |
| 143 | + "feat!: breaking change", |
| 144 | + "BREAKING CHANGE: major change", |
| 145 | + ] |
| 146 | + assert ( |
| 147 | + find_increment_by_callable( |
| 148 | + commit_messages, lambda x: bump_rule.get_increment(x, True) |
| 149 | + ) |
| 150 | + == MAJOR |
| 151 | + ) |
| 152 | + |
| 153 | + def test_mixed_commit_types(self, get_increment): |
| 154 | + commit_messages = [ |
| 155 | + "feat: new feature", |
| 156 | + "fix: bug fix", |
| 157 | + "perf: improve performance", |
| 158 | + "refactor: restructure code", |
| 159 | + ] |
| 160 | + assert find_increment_by_callable(commit_messages, get_increment) == MINOR |
| 161 | + |
| 162 | + def test_commit_with_scope(self, get_increment): |
| 163 | + commit_messages = [ |
| 164 | + "feat(api): add new endpoint", |
| 165 | + "fix(ui): fix button alignment", |
| 166 | + ] |
| 167 | + assert find_increment_by_callable(commit_messages, get_increment) == MINOR |
0 commit comments