From 881ad02adb1945b03306aa1f2339f98d5d977714 Mon Sep 17 00:00:00 2001 From: Sonny V Date: Thu, 6 May 2021 10:27:08 +0200 Subject: [PATCH 1/3] fix(cz/conventional_commits): optionally expect '!' right before ':' in schema_pattern Closes: #381 --- commitizen/cz/conventional_commits/conventional_commits.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index 7d5c27570..6ac62d5ec 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -178,8 +178,8 @@ def schema(self) -> str: def schema_pattern(self) -> str: PATTERN = ( - r"(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)!?" - r"(\(\S+\))?:(\s.*)" + r"(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)" + r"(\(\S+\))?!?:(\s.*)" ) return PATTERN From ba58b22e1f44b9a953dc12fd2132535b35f7568c Mon Sep 17 00:00:00 2001 From: Sonny V Date: Thu, 6 May 2021 11:02:26 +0200 Subject: [PATCH 2/3] test(cz/conventional_commits): test check command and process_commit with conventional commits --- tests/commands/test_check_command.py | 12 ++++++++++-- tests/test_cz_conventional_commits.py | 22 +++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/tests/commands/test_check_command.py b/tests/commands/test_check_command.py index df54c1234..7377a8a38 100644 --- a/tests/commands/test_check_command.py +++ b/tests/commands/test_check_command.py @@ -124,12 +124,19 @@ def test_check_conventional_commit_succeeds(mocker, capsys): assert "Commit validation: successful!" in out -def test_check_no_conventional_commit(config, mocker, tmpdir): +@pytest.mark.parametrize( + "commit_msg", + ( + "feat!(lang): removed polish language", + "no conventional commit", + ), +) +def test_check_no_conventional_commit(commit_msg, config, mocker, tmpdir): with pytest.raises(InvalidCommitMessageError): error_mock = mocker.patch("commitizen.out.error") tempfile = tmpdir.join("temp_commit_file") - tempfile.write("no conventional commit") + tempfile.write(commit_msg) check_cmd = commands.Check( config=config, arguments={"commit_msg_file": tempfile} @@ -141,6 +148,7 @@ def test_check_no_conventional_commit(config, mocker, tmpdir): @pytest.mark.parametrize( "commit_msg", ( + "feat(lang)!: removed polish language", "feat(lang): added polish language", "feat: add polish language", "bump: 0.0.1 -> 1.0.0", diff --git a/tests/test_cz_conventional_commits.py b/tests/test_cz_conventional_commits.py index 62eef11a1..2a239cafe 100644 --- a/tests/test_cz_conventional_commits.py +++ b/tests/test_cz_conventional_commits.py @@ -132,7 +132,23 @@ def test_info(config): assert isinstance(info, str) -def test_process_commit(config): +@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("test(test_scope): this is test msg") - assert message == "this is test msg" + message = conventional_commits.process_commit(commit_message) + assert message == expected_message From e1074115a1eae62326f5e998ed52692b956f8163 Mon Sep 17 00:00:00 2001 From: Sonny V Date: Thu, 6 May 2021 11:03:38 +0200 Subject: [PATCH 3/3] style(tests): format tests --- tests/commands/test_check_command.py | 6 +----- tests/test_cz_conventional_commits.py | 20 ++++++-------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/tests/commands/test_check_command.py b/tests/commands/test_check_command.py index 7377a8a38..ac545e3a6 100644 --- a/tests/commands/test_check_command.py +++ b/tests/commands/test_check_command.py @@ -125,11 +125,7 @@ def test_check_conventional_commit_succeeds(mocker, capsys): @pytest.mark.parametrize( - "commit_msg", - ( - "feat!(lang): removed polish language", - "no conventional commit", - ), + "commit_msg", ("feat!(lang): removed polish language", "no conventional commit",), ) def test_check_no_conventional_commit(commit_msg, config, mocker, tmpdir): with pytest.raises(InvalidCommitMessageError): diff --git a/tests/test_cz_conventional_commits.py b/tests/test_cz_conventional_commits.py index 2a239cafe..e43284a12 100644 --- a/tests/test_cz_conventional_commits.py +++ b/tests/test_cz_conventional_commits.py @@ -132,21 +132,13 @@ def test_info(config): assert isinstance(info, str) -@pytest.mark.parametrize(("commit_message", "expected_message"), +@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", - "", - ), - ] + ("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)