|
3 | 3 | from commitizen.bump_rule import (
|
4 | 4 | ConventionalCommitBumpRule,
|
5 | 5 | OldSchoolBumpRule,
|
| 6 | + _find_highest_increment, |
6 | 7 | find_increment_by_callable,
|
7 | 8 | )
|
8 | 9 | from commitizen.defaults import (
|
@@ -106,6 +107,38 @@ def test_other_commit_types(self, bump_rule):
|
106 | 107 | assert bump_rule.get_increment("build: update build config", False) is None
|
107 | 108 | assert bump_rule.get_increment("ci: update CI pipeline", False) is None
|
108 | 109 |
|
| 110 | + def test_breaking_change_with_refactor(self, bump_rule): |
| 111 | + """Test breaking changes with refactor type commit messages.""" |
| 112 | + # Breaking change with refactor type |
| 113 | + assert ( |
| 114 | + bump_rule.get_increment("refactor!: drop support for Python 2.7", False) |
| 115 | + == MAJOR |
| 116 | + ) |
| 117 | + assert ( |
| 118 | + bump_rule.get_increment("refactor!: drop support for Python 2.7", True) |
| 119 | + == MINOR |
| 120 | + ) |
| 121 | + |
| 122 | + # Breaking change with refactor type and scope |
| 123 | + assert ( |
| 124 | + bump_rule.get_increment( |
| 125 | + "refactor(api)!: remove deprecated endpoints", False |
| 126 | + ) |
| 127 | + == MAJOR |
| 128 | + ) |
| 129 | + assert ( |
| 130 | + bump_rule.get_increment("refactor(api)!: remove deprecated endpoints", True) |
| 131 | + == MINOR |
| 132 | + ) |
| 133 | + |
| 134 | + # Regular refactor (should be PATCH) |
| 135 | + assert ( |
| 136 | + bump_rule.get_increment("refactor: improve code structure", False) == PATCH |
| 137 | + ) |
| 138 | + assert ( |
| 139 | + bump_rule.get_increment("refactor: improve code structure", True) == PATCH |
| 140 | + ) |
| 141 | + |
109 | 142 |
|
110 | 143 | class TestFindIncrementByCallable:
|
111 | 144 | @pytest.fixture
|
@@ -291,6 +324,38 @@ def test_with_find_increment_by_callable(self, old_school_rule):
|
291 | 324 | == MAJOR
|
292 | 325 | )
|
293 | 326 |
|
| 327 | + def test_flexible_bump_map(self, old_school_rule): |
| 328 | + """Test that _find_highest_increment is used correctly in bump map processing.""" |
| 329 | + # Test with multiple matching patterns |
| 330 | + pattern = r"^((?P<major>major)|(?P<minor>minor)|(?P<patch>patch))(?P<scope>\(.+\))?(?P<bang>!)?:" |
| 331 | + bump_map = { |
| 332 | + "major": MAJOR, |
| 333 | + "bang": MAJOR, |
| 334 | + "minor": MINOR, |
| 335 | + "patch": PATCH, |
| 336 | + } |
| 337 | + bump_map_major_version_zero = { |
| 338 | + "major": MINOR, |
| 339 | + "bang": MINOR, |
| 340 | + "minor": MINOR, |
| 341 | + "patch": PATCH, |
| 342 | + } |
| 343 | + rule = OldSchoolBumpRule(pattern, bump_map, bump_map_major_version_zero) |
| 344 | + |
| 345 | + # Test with multiple version tags |
| 346 | + assert rule.get_increment("major!: drop support for Python 2.7", False) == MAJOR |
| 347 | + assert rule.get_increment("major!: drop support for Python 2.7", True) == MINOR |
| 348 | + assert rule.get_increment("major: drop support for Python 2.7", False) == MAJOR |
| 349 | + assert rule.get_increment("major: drop support for Python 2.7", True) == MINOR |
| 350 | + assert rule.get_increment("patch!: drop support for Python 2.7", False) == MAJOR |
| 351 | + assert rule.get_increment("patch!: drop support for Python 2.7", True) == MINOR |
| 352 | + assert rule.get_increment("patch: drop support for Python 2.7", False) == PATCH |
| 353 | + assert rule.get_increment("patch: drop support for Python 2.7", True) == PATCH |
| 354 | + assert rule.get_increment("minor: add new feature", False) == MINOR |
| 355 | + assert rule.get_increment("minor: add new feature", True) == MINOR |
| 356 | + assert rule.get_increment("patch: fix bug", False) == PATCH |
| 357 | + assert rule.get_increment("patch: fix bug", True) == PATCH |
| 358 | + |
294 | 359 |
|
295 | 360 | class TestOldSchoolBumpRuleWithDefault:
|
296 | 361 | @pytest.fixture
|
@@ -378,3 +443,33 @@ def test_with_find_increment_by_callable(self, old_school_rule):
|
378 | 443 | )
|
379 | 444 | == MAJOR
|
380 | 445 | )
|
| 446 | + |
| 447 | + |
| 448 | +def test_find_highest_increment(): |
| 449 | + """Test the _find_highest_increment function.""" |
| 450 | + # Test with single increment |
| 451 | + assert _find_highest_increment([MAJOR]) == MAJOR |
| 452 | + assert _find_highest_increment([MINOR]) == MINOR |
| 453 | + assert _find_highest_increment([PATCH]) == PATCH |
| 454 | + |
| 455 | + # Test with multiple increments |
| 456 | + assert _find_highest_increment([PATCH, MINOR, MAJOR]) == MAJOR |
| 457 | + assert _find_highest_increment([PATCH, MINOR]) == MINOR |
| 458 | + assert _find_highest_increment([PATCH, PATCH]) == PATCH |
| 459 | + |
| 460 | + # Test with None values |
| 461 | + assert _find_highest_increment([None, PATCH]) == PATCH |
| 462 | + assert _find_highest_increment([None, None]) is None |
| 463 | + assert _find_highest_increment([]) is None |
| 464 | + |
| 465 | + # Test with mixed values |
| 466 | + assert _find_highest_increment([None, PATCH, MINOR, MAJOR]) == MAJOR |
| 467 | + assert _find_highest_increment([None, PATCH, MINOR]) == MINOR |
| 468 | + assert _find_highest_increment([None, PATCH]) == PATCH |
| 469 | + |
| 470 | + # Test with empty iterator |
| 471 | + assert _find_highest_increment(iter([])) is None |
| 472 | + |
| 473 | + # Test with generator expression |
| 474 | + assert _find_highest_increment(x for x in [PATCH, MINOR, MAJOR]) == MAJOR |
| 475 | + assert _find_highest_increment(x for x in [None, PATCH, MINOR]) == MINOR |
0 commit comments