forked from commitizen-tools/commitizen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bump_find_increment.py
More file actions
160 lines (137 loc) · 4.93 KB
/
test_bump_find_increment.py
File metadata and controls
160 lines (137 loc) · 4.93 KB
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
158
159
160
"""
CC: Conventional commits
SVE: Semantic version at the end
"""
import pytest
from commitizen import bump
from commitizen.cz.conventional_commits import ConventionalCommitsCz
from commitizen.git import GitCommit
NONE_INCREMENT_CC = [
"docs(README): motivation",
"ci: added travis",
"performance. Remove or disable the reimplemented linters",
"refactor that how this line starts",
]
PATCH_INCREMENTS_CC = [
"fix(setup.py): future is now required for every python version",
"docs(README): motivation",
]
MINOR_INCREMENTS_CC = [
"feat(cli): added version",
"docs(README): motivation",
"fix(setup.py): future is now required for every python version",
"perf: app is much faster",
"refactor: app is much faster",
]
MAJOR_INCREMENTS_BREAKING_CHANGE_CC = [
"feat(cli): added version",
"docs(README): motivation",
"BREAKING CHANGE: `extends` key in config file is now used for extending other config files",
"fix(setup.py): future is now required for every python version",
]
MAJOR_INCREMENTS_BREAKING_CHANGE_ALT_CC = [
"feat(cli): added version",
"docs(README): motivation",
"BREAKING-CHANGE: `extends` key in config file is now used for extending other config files",
"fix(setup.py): future is now required for every python version",
]
MAJOR_INCREMENTS_EXCLAMATION_CC = [
"feat(cli)!: added version",
"docs(README): motivation",
"fix(setup.py): future is now required for every python version",
]
MAJOR_INCREMENTS_EXCLAMATION_CC_SAMPLE_2 = [
"feat(pipeline)!: some text with breaking change"
]
MAJOR_INCREMENTS_EXCLAMATION_OTHER_TYPE_CC = [
"chore!: drop support for Python 3.9",
"docs(README): motivation",
"fix(setup.py): future is now required for every python version",
]
MAJOR_INCREMENTS_EXCLAMATION_OTHER_TYPE_WITH_SCOPE_CC = [
"chore(deps)!: drop support for Python 3.9",
"docs(README): motivation",
"fix(setup.py): future is now required for every python version",
]
PATCH_INCREMENTS_SVE = ["readme motivation PATCH", "fix setup.py PATCH"]
MINOR_INCREMENTS_SVE = [
"readme motivation PATCH",
"fix setup.py PATCH",
"added version to cli MINOR",
]
MAJOR_INCREMENTS_SVE = [
"readme motivation PATCH",
"fix setup.py PATCH",
"added version to cli MINOR",
"extends key is used for other config files MAJOR",
]
semantic_version_pattern = r"(MAJOR|MINOR|PATCH)"
semantic_version_map = {"MAJOR": "MAJOR", "MINOR": "MINOR", "PATCH": "PATCH"}
@pytest.mark.parametrize(
("messages", "expected_type"),
[
(PATCH_INCREMENTS_CC, "PATCH"),
(MINOR_INCREMENTS_CC, "MINOR"),
(MAJOR_INCREMENTS_BREAKING_CHANGE_CC, "MAJOR"),
(MAJOR_INCREMENTS_BREAKING_CHANGE_ALT_CC, "MAJOR"),
(MAJOR_INCREMENTS_EXCLAMATION_OTHER_TYPE_CC, "MAJOR"),
(MAJOR_INCREMENTS_EXCLAMATION_OTHER_TYPE_WITH_SCOPE_CC, "MAJOR"),
(MAJOR_INCREMENTS_EXCLAMATION_CC, "MAJOR"),
(MAJOR_INCREMENTS_EXCLAMATION_CC_SAMPLE_2, "MAJOR"),
(NONE_INCREMENT_CC, None),
],
)
def test_find_increment(messages, expected_type):
commits = [GitCommit(rev="test", title=message) for message in messages]
increment_type = bump.find_increment(
commits,
regex=ConventionalCommitsCz.bump_pattern,
increments_map=ConventionalCommitsCz.bump_map,
)
assert increment_type == expected_type
def test_find_increment_with_ignored_rev():
messages = [
"docs(README): motivation",
"feat: this should not be bumped because of the ignore_bump_rev_list",
]
commits = [
GitCommit(rev="test1", title=messages[0]),
GitCommit(rev="test2", title=messages[1]),
]
increment_type = bump.find_increment(
commits,
regex=ConventionalCommitsCz.bump_pattern,
increments_map=ConventionalCommitsCz.bump_map,
ignore_bump_rev_list=["test2"],
)
assert increment_type is None
def test_find_increment_with_ignored_author():
messages = [
"feat: this should not be bumped because of the ignore_bump_author_list",
"docs(README): motivation",
]
commits = [
GitCommit(rev="test1", title=messages[0], author="alice"),
GitCommit(rev="test2", title=messages[1], author="bob"),
]
increment_type = bump.find_increment(
commits,
regex=ConventionalCommitsCz.bump_pattern,
increments_map=ConventionalCommitsCz.bump_map,
ignore_bump_author_list=["alice"],
)
assert increment_type is None
@pytest.mark.parametrize(
("messages", "expected_type"),
[
(PATCH_INCREMENTS_SVE, "PATCH"),
(MINOR_INCREMENTS_SVE, "MINOR"),
(MAJOR_INCREMENTS_SVE, "MAJOR"),
],
)
def test_find_increment_sve(messages, expected_type):
commits = [GitCommit(rev="test", title=message) for message in messages]
increment_type = bump.find_increment(
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
)
assert increment_type == expected_type