Skip to content

fix(cz/exceptions): Fix AnswerRequiredException not caught #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from commitizen import commands, config, out


logger = logging.getLogger(__name__)
data = {
"prog": "cz",
Expand Down
5 changes: 2 additions & 3 deletions commitizen/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from .bump import Bump
from .commit import Commit
from .check import Check
from .commit import Commit
from .example import Example
from .info import Info
from .list_cz import ListCz
from .schema import Schema
from .version import Version

__all__ = ("Bump", "Check", "Commit", "Example", "Info", "ListCz", "Schema",
"Version")
__all__ = ("Bump", "Check", "Commit", "Example", "Info", "ListCz", "Schema", "Version")
8 changes: 5 additions & 3 deletions commitizen/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

from commitizen import out

PATTERN = (r'(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)'
r'(\([\w\-]+\))?:\s.*')
PATTERN = (
r"(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)"
r"(\([\w\-]+\))?:\s.*"
)
NO_COMMIT_MSG = 3
INVALID_COMMIT_MSG = 5

Expand Down Expand Up @@ -46,7 +48,7 @@ def __call__(self):

def _get_commit_msg(self):
temp_filename: str = self.arguments.get("commit_msg_file")
return open(temp_filename, 'r').read()
return open(temp_filename, "r").read()

def _is_conventional(self, pattern, commit_msg):
return re.match(PATTERN, commit_msg)
2 changes: 1 addition & 1 deletion commitizen/cz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pkgutil

from commitizen.cz.conventional_commits import ConventionalCommitsCz
from commitizen.cz.jira import JiraSmartCz
from commitizen.cz.customize import CustomizeCommitsCz
from commitizen.cz.jira import JiraSmartCz

registry = {
"cz_conventional_commits": ConventionalCommitsCz,
Expand Down
2 changes: 1 addition & 1 deletion commitizen/cz/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ class CzException(Exception):
...


class AnswerRequiredError(Exception):
class AnswerRequiredError(CzException):
...
2 changes: 1 addition & 1 deletion tests/test_bump_command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import errno
import os
import shutil
import stat
import errno
import sys
import uuid
from pathlib import Path
Expand Down
15 changes: 5 additions & 10 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,11 @@ def test_check_no_conventional_commit(mocker):
with get_temp_dir() as dir:

tempfile = os.path.join(dir, "temp_commit_file")
with open(tempfile, 'w') as f:
with open(tempfile, "w") as f:
f.write("no conventional commit")

check_cmd = commands.Check(
config=config,
arguments={"commit_msg_file": tempfile}
config=config, arguments={"commit_msg_file": tempfile}
)
check_cmd()
error_mock.assert_called_once()
Expand All @@ -195,12 +194,11 @@ def test_check_conventional_commit(mocker):
with get_temp_dir() as dir:

tempfile = os.path.join(dir, "temp_commit_file")
with open(tempfile, 'w') as f:
with open(tempfile, "w") as f:
f.write("feat(lang): added polish language")

check_cmd = commands.Check(
config=config,
arguments={"commit_msg_file": tempfile}
config=config, arguments={"commit_msg_file": tempfile}
)

check_cmd()
Expand All @@ -209,7 +207,4 @@ def test_check_conventional_commit(mocker):

def test_check_command_when_commit_file_not_found():
with pytest.raises(FileNotFoundError):
commands.Check(
config=config,
arguments={"commit_msg_file": ""}
)()
commands.Check(config=config, arguments={"commit_msg_file": ""})()
2 changes: 1 addition & 1 deletion tests/test_cz_customize.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest
from tomlkit import parse

from commitizen.cz.customize import CustomizeCommitsCz
from commitizen.config import Config
from commitizen.cz.customize import CustomizeCommitsCz


@pytest.fixture(scope="module")
Expand Down