-
-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathtest_cz_conventional_commits.py
155 lines (120 loc) · 4.61 KB
/
test_cz_conventional_commits.py
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
import pytest
from commitizen.cz.conventional_commits.conventional_commits import (
ConventionalCommitsCz,
parse_scope,
parse_subject,
)
from commitizen.cz.exceptions import AnswerRequiredError
valid_scopes = ["", "simple", "dash-separated", "camelCaseUPPERCASE"]
scopes_transformations = [["with spaces", "with-spaces"], [None, ""]]
valid_subjects = ["this is a normal text", "aword"]
subjects_transformations = [["with dot.", "with dot"]]
invalid_subjects = ["", " ", ".", " .", "", None]
def test_parse_scope_valid_values():
for valid_scope in valid_scopes:
assert valid_scope == parse_scope(valid_scope)
def test_scopes_transformations():
for scopes_transformation in scopes_transformations:
invalid_scope, transformed_scope = scopes_transformation
assert transformed_scope == parse_scope(invalid_scope)
def test_parse_subject_valid_values():
for valid_subject in valid_subjects:
assert valid_subject == parse_subject(valid_subject)
def test_parse_subject_invalid_values():
for valid_subject in invalid_subjects:
with pytest.raises(AnswerRequiredError):
parse_subject(valid_subject)
def test_subject_transformations():
for subject_transformation in subjects_transformations:
invalid_subject, transformed_subject = subject_transformation
assert transformed_subject == parse_subject(invalid_subject)
def test_questions(config):
conventional_commits = ConventionalCommitsCz(config)
questions = conventional_commits.questions()
assert isinstance(questions, list)
assert isinstance(questions[0], dict)
def test_choices_all_have_keyboard_shortcuts(config):
conventional_commits = ConventionalCommitsCz(config)
questions = conventional_commits.questions()
list_questions = (q for q in questions if q["type"] == "list")
for select in list_questions:
assert all("key" in choice for choice in select["choices"])
def test_small_answer(config):
conventional_commits = ConventionalCommitsCz(config)
answers = {
"prefix": "fix",
"scope": "users",
"subject": "email pattern corrected",
"is_breaking_change": False,
"body": "",
"footer": "",
}
message = conventional_commits.message(answers)
assert message == "fix(users): email pattern corrected"
def test_long_answer(config):
conventional_commits = ConventionalCommitsCz(config)
answers = {
"prefix": "fix",
"scope": "users",
"subject": "email pattern corrected",
"is_breaking_change": False,
"body": "complete content",
"footer": "closes #24",
}
message = conventional_commits.message(answers)
assert (
message
== "fix(users): email pattern corrected\n\ncomplete content\n\ncloses #24" # noqa
)
def test_breaking_change_in_footer(config):
conventional_commits = ConventionalCommitsCz(config)
answers = {
"prefix": "fix",
"scope": "users",
"subject": "email pattern corrected",
"is_breaking_change": True,
"body": "complete content",
"footer": "migrate by renaming user to users",
}
message = conventional_commits.message(answers)
print(message)
assert (
message
== "fix(users): email pattern corrected\n\ncomplete content\n\nBREAKING CHANGE: migrate by renaming user to users" # noqa
)
def test_example(config):
"""just testing a string is returned. not the content"""
conventional_commits = ConventionalCommitsCz(config)
example = conventional_commits.example()
assert isinstance(example, str)
def test_schema(config):
"""just testing a string is returned. not the content"""
conventional_commits = ConventionalCommitsCz(config)
schema = conventional_commits.schema()
assert isinstance(schema, str)
def test_info(config):
"""just testing a string is returned. not the content"""
conventional_commits = ConventionalCommitsCz(config)
info = conventional_commits.info()
assert isinstance(info, str)
@pytest.mark.parametrize(
("commit_message", "expected_message"),
[
(
"test(test_scope): this is test msg",
"this is test msg",
),
(
"test(test_scope)!: this is test msg",
"this is test msg",
),
(
"test!(test_scope): this is test msg",
"",
),
],
)
def test_process_commit(commit_message, expected_message, config):
conventional_commits = ConventionalCommitsCz(config)
message = conventional_commits.process_commit(commit_message)
assert message == expected_message