| 1 |
""" |
| 2 |
CC: Conventional commits |
| 3 |
SVE: Semantic version at the end |
| 4 |
""" |
| 5 |
|
| 6 |
import pytest |
| 7 |
|
| 8 |
from commitizen import bump |
| 9 |
from commitizen.cz.conventional_commits import ConventionalCommitsCz |
| 10 |
from commitizen.git import GitCommit |
| 11 |
|
| 12 |
NONE_INCREMENT_CC = [ |
| 13 |
"docs(README): motivation", |
| 14 |
"ci: added travis", |
| 15 |
"performance. Remove or disable the reimplemented linters", |
| 16 |
"refactor that how this line starts", |
| 17 |
] |
| 18 |
|
| 19 |
PATCH_INCREMENTS_CC = [ |
| 20 |
"fix(setup.py): future is now required for every python version", |
| 21 |
"docs(README): motivation", |
| 22 |
] |
| 23 |
|
| 24 |
MINOR_INCREMENTS_CC = [ |
| 25 |
"feat(cli): added version", |
| 26 |
"docs(README): motivation", |
| 27 |
"fix(setup.py): future is now required for every python version", |
| 28 |
"perf: app is much faster", |
| 29 |
"refactor: app is much faster", |
| 30 |
] |
| 31 |
|
| 32 |
MAJOR_INCREMENTS_BREAKING_CHANGE_CC = [ |
| 33 |
"feat(cli): added version", |
| 34 |
"docs(README): motivation", |
| 35 |
"BREAKING CHANGE: `extends` key in config file is now used for extending other config files", |
| 36 |
"fix(setup.py): future is now required for every python version", |
| 37 |
] |
| 38 |
|
| 39 |
MAJOR_INCREMENTS_BREAKING_CHANGE_ALT_CC = [ |
| 40 |
"feat(cli): added version", |
| 41 |
"docs(README): motivation", |
| 42 |
"BREAKING-CHANGE: `extends` key in config file is now used for extending other config files", |
| 43 |
"fix(setup.py): future is now required for every python version", |
| 44 |
] |
| 45 |
|
| 46 |
MAJOR_INCREMENTS_EXCLAMATION_CC = [ |
| 47 |
"feat(cli)!: added version", |
| 48 |
"docs(README): motivation", |
| 49 |
"fix(setup.py): future is now required for every python version", |
| 50 |
] |
| 51 |
|
| 52 |
MAJOR_INCREMENTS_EXCLAMATION_CC_SAMPLE_2 = [ |
| 53 |
"feat(pipeline)!: some text with breaking change" |
| 54 |
] |
| 55 |
|
| 56 |
MAJOR_INCREMENTS_EXCLAMATION_OTHER_TYPE_CC = [ |
| 57 |
"chore!: drop support for Python 3.9", |
| 58 |
"docs(README): motivation", |
| 59 |
"fix(setup.py): future is now required for every python version", |
| 60 |
] |
| 61 |
|
| 62 |
MAJOR_INCREMENTS_EXCLAMATION_OTHER_TYPE_WITH_SCOPE_CC = [ |
| 63 |
"chore(deps)!: drop support for Python 3.9", |
| 64 |
"docs(README): motivation", |
| 65 |
"fix(setup.py): future is now required for every python version", |
| 66 |
] |
| 67 |
|
| 68 |
PATCH_INCREMENTS_SVE = ["readme motivation PATCH", "fix setup.py PATCH"] |
| 69 |
|
| 70 |
MINOR_INCREMENTS_SVE = [ |
| 71 |
"readme motivation PATCH", |
| 72 |
"fix setup.py PATCH", |
| 73 |
"added version to cli MINOR", |
| 74 |
] |
| 75 |
|
| 76 |
MAJOR_INCREMENTS_SVE = [ |
| 77 |
"readme motivation PATCH", |
| 78 |
"fix setup.py PATCH", |
| 79 |
"added version to cli MINOR", |
| 80 |
"extends key is used for other config files MAJOR", |
| 81 |
] |
| 82 |
|
| 83 |
semantic_version_pattern = r"(MAJOR|MINOR|PATCH)" |
| 84 |
semantic_version_map = {"MAJOR": "MAJOR", "MINOR": "MINOR", "PATCH": "PATCH"} |
| 85 |
|
| 86 |
|
| 87 |
@pytest.mark.parametrize( |
| 88 |
("messages", "expected_type"), |
| 89 |
[ |
| 90 |
(PATCH_INCREMENTS_CC, "PATCH"), |
| 91 |
(MINOR_INCREMENTS_CC, "MINOR"), |
| 92 |
(MAJOR_INCREMENTS_BREAKING_CHANGE_CC, "MAJOR"), |
| 93 |
(MAJOR_INCREMENTS_BREAKING_CHANGE_ALT_CC, "MAJOR"), |
| 94 |
(MAJOR_INCREMENTS_EXCLAMATION_OTHER_TYPE_CC, "MAJOR"), |
| 95 |
(MAJOR_INCREMENTS_EXCLAMATION_OTHER_TYPE_WITH_SCOPE_CC, "MAJOR"), |
| 96 |
(MAJOR_INCREMENTS_EXCLAMATION_CC, "MAJOR"), |
| 97 |
(MAJOR_INCREMENTS_EXCLAMATION_CC_SAMPLE_2, "MAJOR"), |
| 98 |
(NONE_INCREMENT_CC, None), |
| 99 |
], |
| 100 |
) |
| 101 |
def test_find_increment(messages, expected_type): |
| 102 |
commits = [GitCommit(rev="test", title=message) for message in messages] |
| 103 |
increment_type = bump.find_increment( |
| 104 |
commits, |
| 105 |
regex=ConventionalCommitsCz.bump_pattern, |
| 106 |
increments_map=ConventionalCommitsCz.bump_map, |
| 107 |
) |
| 108 |
assert increment_type == expected_type |
| 109 |
|
| 110 |
|
| 111 |
@pytest.mark.parametrize( |
| 112 |
("messages", "expected_type"), |
| 113 |
[ |
| 114 |
(PATCH_INCREMENTS_SVE, "PATCH"), |
| 115 |
(MINOR_INCREMENTS_SVE, "MINOR"), |
| 116 |
(MAJOR_INCREMENTS_SVE, "MAJOR"), |
| 117 |
], |
| 118 |
) |
| 119 |
def test_find_increment_sve(messages, expected_type): |
| 120 |
commits = [GitCommit(rev="test", title=message) for message in messages] |
| 121 |
increment_type = bump.find_increment( |
| 122 |
commits, regex=semantic_version_pattern, increments_map=semantic_version_map |
| 123 |
) |
| 124 |
assert increment_type == expected_type |