|
| 1 | +import pytest |
| 2 | + |
| 3 | +from commitizen.bump_rule import DefaultBumpRule |
| 4 | +from commitizen.defaults import MAJOR, MINOR, PATCH |
| 5 | + |
| 6 | + |
| 7 | +@pytest.fixture |
| 8 | +def bump_rule(): |
| 9 | + return DefaultBumpRule() |
| 10 | + |
| 11 | + |
| 12 | +class TestDefaultBumpRule: |
| 13 | + def test_feat_commit(self, bump_rule): |
| 14 | + assert bump_rule.get_increment("feat: add new feature", False) == MINOR |
| 15 | + assert bump_rule.get_increment("feat: add new feature", True) == MINOR |
| 16 | + |
| 17 | + def test_fix_commit(self, bump_rule): |
| 18 | + assert bump_rule.get_increment("fix: fix bug", False) == PATCH |
| 19 | + assert bump_rule.get_increment("fix: fix bug", True) == PATCH |
| 20 | + |
| 21 | + def test_perf_commit(self, bump_rule): |
| 22 | + assert bump_rule.get_increment("perf: improve performance", False) == PATCH |
| 23 | + assert bump_rule.get_increment("perf: improve performance", True) == PATCH |
| 24 | + |
| 25 | + def test_refactor_commit(self, bump_rule): |
| 26 | + assert bump_rule.get_increment("refactor: restructure code", False) == PATCH |
| 27 | + assert bump_rule.get_increment("refactor: restructure code", True) == PATCH |
| 28 | + |
| 29 | + def test_breaking_change_with_bang(self, bump_rule): |
| 30 | + assert bump_rule.get_increment("feat!: breaking change", False) == MINOR |
| 31 | + assert bump_rule.get_increment("feat!: breaking change", True) == MAJOR |
| 32 | + |
| 33 | + def test_breaking_change_type(self, bump_rule): |
| 34 | + assert bump_rule.get_increment("BREAKING CHANGE: major change", False) == MINOR |
| 35 | + assert bump_rule.get_increment("BREAKING CHANGE: major change", True) == MAJOR |
| 36 | + |
| 37 | + def test_commit_with_scope(self, bump_rule): |
| 38 | + assert bump_rule.get_increment("feat(api): add new endpoint", False) == MINOR |
| 39 | + assert bump_rule.get_increment("fix(ui): fix button alignment", False) == PATCH |
| 40 | + |
| 41 | + def test_commit_with_complex_scopes(self, bump_rule): |
| 42 | + # Test with multiple word scopes |
| 43 | + assert ( |
| 44 | + bump_rule.get_increment("feat(user_management): add user roles", False) |
| 45 | + == MINOR |
| 46 | + ) |
| 47 | + assert ( |
| 48 | + bump_rule.get_increment("fix(database_connection): handle timeout", False) |
| 49 | + == PATCH |
| 50 | + ) |
| 51 | + |
| 52 | + # Test with nested scopes |
| 53 | + assert ( |
| 54 | + bump_rule.get_increment("feat(api/auth): implement OAuth", False) == MINOR |
| 55 | + ) |
| 56 | + assert ( |
| 57 | + bump_rule.get_increment("fix(ui/components): fix dropdown", False) == PATCH |
| 58 | + ) |
| 59 | + |
| 60 | + # Test with breaking changes and scopes |
| 61 | + assert ( |
| 62 | + bump_rule.get_increment("feat(api)!: remove deprecated endpoints", False) |
| 63 | + == MINOR |
| 64 | + ) |
| 65 | + assert ( |
| 66 | + bump_rule.get_increment("feat(api)!: remove deprecated endpoints", True) |
| 67 | + == MAJOR |
| 68 | + ) |
| 69 | + |
| 70 | + # Test with BREAKING CHANGE and scopes |
| 71 | + assert ( |
| 72 | + bump_rule.get_increment( |
| 73 | + "BREAKING CHANGE(api): remove deprecated endpoints", False |
| 74 | + ) |
| 75 | + == MINOR |
| 76 | + ) |
| 77 | + assert ( |
| 78 | + bump_rule.get_increment( |
| 79 | + "BREAKING CHANGE(api): remove deprecated endpoints", True |
| 80 | + ) |
| 81 | + == MAJOR |
| 82 | + ) |
| 83 | + |
| 84 | + def test_invalid_commit_message(self, bump_rule): |
| 85 | + assert bump_rule.get_increment("invalid commit message", False) is None |
| 86 | + assert bump_rule.get_increment("", False) is None |
| 87 | + assert bump_rule.get_increment("feat", False) is None |
| 88 | + |
| 89 | + def test_other_commit_types(self, bump_rule): |
| 90 | + # These commit types should not trigger any version bump |
| 91 | + assert bump_rule.get_increment("docs: update documentation", False) is None |
| 92 | + assert bump_rule.get_increment("style: format code", False) is None |
| 93 | + assert bump_rule.get_increment("test: add unit tests", False) is None |
| 94 | + assert bump_rule.get_increment("build: update build config", False) is None |
| 95 | + assert bump_rule.get_increment("ci: update CI pipeline", False) is None |
0 commit comments