Skip to content

Commit ba58b22

Browse files
committed
test(cz/conventional_commits): test check command and process_commit with conventional commits
1 parent 881ad02 commit ba58b22

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

tests/commands/test_check_command.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,19 @@ def test_check_conventional_commit_succeeds(mocker, capsys):
124124
assert "Commit validation: successful!" in out
125125

126126

127-
def test_check_no_conventional_commit(config, mocker, tmpdir):
127+
@pytest.mark.parametrize(
128+
"commit_msg",
129+
(
130+
"feat!(lang): removed polish language",
131+
"no conventional commit",
132+
),
133+
)
134+
def test_check_no_conventional_commit(commit_msg, config, mocker, tmpdir):
128135
with pytest.raises(InvalidCommitMessageError):
129136
error_mock = mocker.patch("commitizen.out.error")
130137

131138
tempfile = tmpdir.join("temp_commit_file")
132-
tempfile.write("no conventional commit")
139+
tempfile.write(commit_msg)
133140

134141
check_cmd = commands.Check(
135142
config=config, arguments={"commit_msg_file": tempfile}
@@ -141,6 +148,7 @@ def test_check_no_conventional_commit(config, mocker, tmpdir):
141148
@pytest.mark.parametrize(
142149
"commit_msg",
143150
(
151+
"feat(lang)!: removed polish language",
144152
"feat(lang): added polish language",
145153
"feat: add polish language",
146154
"bump: 0.0.1 -> 1.0.0",

tests/test_cz_conventional_commits.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,23 @@ def test_info(config):
132132
assert isinstance(info, str)
133133

134134

135-
def test_process_commit(config):
135+
@pytest.mark.parametrize(("commit_message", "expected_message"),
136+
[
137+
(
138+
"test(test_scope): this is test msg",
139+
"this is test msg",
140+
),
141+
(
142+
"test(test_scope)!: this is test msg",
143+
"this is test msg",
144+
),
145+
(
146+
"test!(test_scope): this is test msg",
147+
"",
148+
),
149+
]
150+
)
151+
def test_process_commit(commit_message, expected_message, config):
136152
conventional_commits = ConventionalCommitsCz(config)
137-
message = conventional_commits.process_commit("test(test_scope): this is test msg")
138-
assert message == "this is test msg"
153+
message = conventional_commits.process_commit(commit_message)
154+
assert message == expected_message

0 commit comments

Comments
 (0)