|
28 | 28 |
|
29 | 29 | COMMIT_LOG = [ |
30 | 30 | "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", |
32 | 32 | "refactor(git): remove unnecessary dot between git range", |
33 | 33 | "bump: version 1.16.3 → 1.16.4", |
34 | 34 | ( |
@@ -79,46 +79,21 @@ def test_check_jira_fails(mocker: MockFixture, util: UtilFixture): |
79 | 79 | assert "commit validation: failed!" in str(excinfo.value) |
80 | 80 |
|
81 | 81 |
|
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 |
108 | 93 | ): |
109 | 94 | mocker.patch( |
110 | 95 | "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), |
122 | 97 | ) |
123 | 98 | util.run_cli("-n", "cz_jira", "check", "--commit-msg-file", "some_file") |
124 | 99 | out, _ = capsys.readouterr() |
@@ -237,9 +212,7 @@ def test_check_a_range_of_failed_git_commits(config, mocker: MockFixture): |
237 | 212 | assert all([msg in str(excinfo.value) for msg in ill_formatted_commits_msgs]) |
238 | 213 |
|
239 | 214 |
|
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): |
243 | 216 | commands.Check( |
244 | 217 | config=config, arguments={"message": "fix(scope): some commit message"} |
245 | 218 | )() |
@@ -335,28 +308,29 @@ def test_check_command_with_comment_in_message_file( |
335 | 308 | def test_check_conventional_commit_succeed_with_git_diff( |
336 | 309 | mocker, capsys, util: UtilFixture |
337 | 310 | ): |
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 | | - ) |
357 | 311 | mocker.patch( |
358 | 312 | "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 | + ), |
360 | 334 | ) |
361 | 335 | util.run_cli("check", "--commit-msg-file", "some_file") |
362 | 336 | out, _ = capsys.readouterr() |
@@ -407,7 +381,7 @@ def test_check_command_with_config_message_length_limit_exceeded(config): |
407 | 381 |
|
408 | 382 |
|
409 | 383 | def test_check_command_cli_overrides_config_message_length_limit( |
410 | | - config, success_mock: MockType, mocker: MockFixture |
| 384 | + config, success_mock: MockType |
411 | 385 | ): |
412 | 386 | message = "fix(scope): some commit message" |
413 | 387 | config.settings["message_length_limit"] = len(message) - 1 |
|
0 commit comments