Skip to content

Commit f6aef69

Browse files
test(check): shorten tests and dedup logic (#1807)
1 parent 38483e9 commit f6aef69

File tree

1 file changed

+36
-62
lines changed

1 file changed

+36
-62
lines changed

tests/commands/test_check_command.py

Lines changed: 36 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
COMMIT_LOG = [
3030
"refactor: A code change that neither fixes a bug nor adds a feature",
31-
r"refactor(cz/connventional_commit): use \S to check scope",
31+
r"refactor(cz/conventional_commit): use \S to check scope",
3232
"refactor(git): remove unnecessary dot between git range",
3333
"bump: version 1.16.3 → 1.16.4",
3434
(
@@ -79,46 +79,21 @@ def test_check_jira_fails(mocker: MockFixture, util: UtilFixture):
7979
assert "commit validation: failed!" in str(excinfo.value)
8080

8181

82-
def test_check_jira_command_after_issue_one_space(
83-
mocker: MockFixture, capsys, util: UtilFixture
84-
):
85-
mocker.patch(
86-
"commitizen.commands.check.open",
87-
mocker.mock_open(read_data="JR-23 #command some arguments etc"),
88-
)
89-
util.run_cli("-n", "cz_jira", "check", "--commit-msg-file", "some_file")
90-
out, _ = capsys.readouterr()
91-
assert "Commit validation: successful!" in out
92-
93-
94-
def test_check_jira_command_after_issue_two_spaces(
95-
mocker: MockFixture, capsys, util: UtilFixture
96-
):
97-
mocker.patch(
98-
"commitizen.commands.check.open",
99-
mocker.mock_open(read_data="JR-2 #command some arguments etc"),
100-
)
101-
util.run_cli("-n", "cz_jira", "check", "--commit-msg-file", "some_file")
102-
out, _ = capsys.readouterr()
103-
assert "Commit validation: successful!" in out
104-
105-
106-
def test_check_jira_text_between_issue_and_command(
107-
mocker: MockFixture, capsys, util: UtilFixture
82+
@pytest.mark.parametrize(
83+
"commit_msg",
84+
[
85+
"JR-23 #command some arguments etc",
86+
"JR-2 #command some arguments etc",
87+
"JR-234 some text #command some arguments etc",
88+
"JRA-23 some text #command1 args #command2 args",
89+
],
90+
)
91+
def test_check_jira_command_after_issue(
92+
mocker: MockFixture, capsys, util: UtilFixture, commit_msg: str
10893
):
10994
mocker.patch(
11095
"commitizen.commands.check.open",
111-
mocker.mock_open(read_data="JR-234 some text #command some arguments etc"),
112-
)
113-
util.run_cli("-n", "cz_jira", "check", "--commit-msg-file", "some_file")
114-
out, _ = capsys.readouterr()
115-
assert "Commit validation: successful!" in out
116-
117-
118-
def test_check_jira_multiple_commands(mocker: MockFixture, capsys, util: UtilFixture):
119-
mocker.patch(
120-
"commitizen.commands.check.open",
121-
mocker.mock_open(read_data="JRA-23 some text #command1 args #command2 args"),
96+
mocker.mock_open(read_data=commit_msg),
12297
)
12398
util.run_cli("-n", "cz_jira", "check", "--commit-msg-file", "some_file")
12499
out, _ = capsys.readouterr()
@@ -237,9 +212,7 @@ def test_check_a_range_of_failed_git_commits(config, mocker: MockFixture):
237212
assert all([msg in str(excinfo.value) for msg in ill_formatted_commits_msgs])
238213

239214

240-
def test_check_command_with_valid_message(
241-
config, success_mock: MockType, mocker: MockFixture
242-
):
215+
def test_check_command_with_valid_message(config, success_mock: MockType):
243216
commands.Check(
244217
config=config, arguments={"message": "fix(scope): some commit message"}
245218
)()
@@ -335,28 +308,29 @@ def test_check_command_with_comment_in_message_file(
335308
def test_check_conventional_commit_succeed_with_git_diff(
336309
mocker, capsys, util: UtilFixture
337310
):
338-
commit_msg = (
339-
"feat: This is a test commit\n"
340-
"# Please enter the commit message for your changes. Lines starting\n"
341-
"# with '#' will be ignored, and an empty message aborts the commit.\n"
342-
"#\n"
343-
"# On branch ...\n"
344-
"# Changes to be committed:\n"
345-
"# modified: ...\n"
346-
"#\n"
347-
"# ------------------------ >8 ------------------------\n"
348-
"# Do not modify or remove the line above.\n"
349-
"# Everything below it will be ignored.\n"
350-
"diff --git a/... b/...\n"
351-
"index f1234c..1c5678 1234\n"
352-
"--- a/...\n"
353-
"+++ b/...\n"
354-
"@@ -92,3 +92,4 @@ class Command(BaseCommand):\n"
355-
'+ "this is a test"\n'
356-
)
357311
mocker.patch(
358312
"commitizen.commands.check.open",
359-
mocker.mock_open(read_data=commit_msg),
313+
mocker.mock_open(
314+
read_data=(
315+
"feat: This is a test commit\n"
316+
"# Please enter the commit message for your changes. Lines starting\n"
317+
"# with '#' will be ignored, and an empty message aborts the commit.\n"
318+
"#\n"
319+
"# On branch ...\n"
320+
"# Changes to be committed:\n"
321+
"# modified: ...\n"
322+
"#\n"
323+
"# ------------------------ >8 ------------------------\n"
324+
"# Do not modify or remove the line above.\n"
325+
"# Everything below it will be ignored.\n"
326+
"diff --git a/... b/...\n"
327+
"index f1234c..1c5678 1234\n"
328+
"--- a/...\n"
329+
"+++ b/...\n"
330+
"@@ -92,3 +92,4 @@ class Command(BaseCommand):\n"
331+
'+ "this is a test"\n'
332+
)
333+
),
360334
)
361335
util.run_cli("check", "--commit-msg-file", "some_file")
362336
out, _ = capsys.readouterr()
@@ -407,7 +381,7 @@ def test_check_command_with_config_message_length_limit_exceeded(config):
407381

408382

409383
def test_check_command_cli_overrides_config_message_length_limit(
410-
config, success_mock: MockType, mocker: MockFixture
384+
config, success_mock: MockType
411385
):
412386
message = "fix(scope): some commit message"
413387
config.settings["message_length_limit"] = len(message) - 1

0 commit comments

Comments
 (0)