Skip to content
Open
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
14 changes: 7 additions & 7 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ And the correspondent example for a yaml file:
commitizen:
name: cz_customize
customize:
message_template: "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
message_template: '{{change_type}}:{% if show_message %} {{message}}{% endif %}'
example: 'feature: this feature enable customize through config file'
schema: "<type>: <body>"
schema_pattern: "(feature|bug fix):(\\s.*)"
bump_pattern: "^(break|new|fix|hotfix)"
commit_parser: "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?"
changelog_pattern: "^(feature|bug fix)?(!)?"
schema: '<type>: <body>'
schema_pattern: '(feature|bug fix):(\\s.*)'
bump_pattern: '^(break|new|fix|hotfix)'
commit_parser: '^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?'
changelog_pattern: '^(feature|bug fix)?(!)?'
Comment on lines +113 to +119
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why we need to change it 🤔

change_type_map:
feature: Feat
bug fix: Fix
Expand All @@ -125,7 +125,7 @@ commitizen:
new: MINOR
fix: PATCH
hotfix: PATCH
change_type_order: ["BREAKING CHANGE", "feat", "fix", "refactor", "perf"]
change_type_order: ['BREAKING CHANGE', 'feat', 'fix', 'refactor', 'perf']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

info_path: cz_customize_info.txt
info: This is customized info
questions:
Expand Down
62 changes: 62 additions & 0 deletions tests/commands/test_commit_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,68 @@ def test_commit_when_nothing_to_commit(config, mocker: MockFixture):
assert "No files added to staging!" in str(excinfo.value)


@pytest.mark.usefixtures("staging_is_clean")
def test_commit_when_nothing_added_to_commit(config, mocker: MockFixture):
prompt_mock = mocker.patch("questionary.prompt")
prompt_mock.return_value = {
"prefix": "feat",
"subject": "user created",
"scope": "",
"is_breaking_change": False,
"body": "",
"footer": "",
}

commit_mock = mocker.patch("commitizen.git.commit")
commit_mock.return_value = cmd.Command(
'nothing added to commit but untracked files present (use "git add" to track)',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might encounter issue if the language is not set to en_US. probably worth setting it up for this test

"",
b"",
b"",
0,
)

error_mock = mocker.patch("commitizen.out.error")

commands.Commit(config, {"all": False})()

prompt_mock.assert_called_once()
error_mock.assert_called_once()

assert "nothing added" in error_mock.call_args[0][0]


@pytest.mark.usefixtures("staging_is_clean")
def test_commit_when_no_changes_added_to_commit(config, mocker: MockFixture):
prompt_mock = mocker.patch("questionary.prompt")
prompt_mock.return_value = {
"prefix": "feat",
"subject": "user created",
"scope": "",
"is_breaking_change": False,
"body": "",
"footer": "",
}

commit_mock = mocker.patch("commitizen.git.commit")
commit_mock.return_value = cmd.Command(
'no changes added to commit (use "git add" and/or "git commit -a")',
"",
b"",
b"",
0,
)

error_mock = mocker.patch("commitizen.out.error")

commands.Commit(config, {"all": False})()

prompt_mock.assert_called_once()
error_mock.assert_called_once()

assert "no changes added to commit" in error_mock.call_args[0][0]


@pytest.mark.usefixtures("staging_is_clean")
def test_commit_with_allow_empty(config, mocker: MockFixture):
prompt_mock = mocker.patch("questionary.prompt")
Expand Down
16 changes: 11 additions & 5 deletions tests/test_cz_customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,22 @@
- commitizen/__version__.py
- pyproject.toml
customize:
message_template: "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
message_template: '{{change_type}}:{% if show_message %} {{message}}{% endif %}'
example: 'feature: this feature enables customization through a config file'
schema: "<type>: <body>"
schema_pattern: "(feature|bug fix):(\\s.*)"
bump_pattern: "^(break|new|fix|hotfix)"
schema: '<type>: <body>'
schema_pattern: '(feature|bug fix):(\\s.*)'
bump_pattern: '^(break|new|fix|hotfix)'
commit_parser: '^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?'
changelog_pattern: '^(feature|bug fix)?(!)?'
change_type_map:
feature: Feat
bug fix: Fix
bump_map:
break: MAJOR
new: MINOR
fix: PATCH
hotfix: PATCH
change_type_order: ["perf", "BREAKING CHANGE", "feat", "fix", "refactor"]
change_type_order: ['perf', 'BREAKING CHANGE', 'feat', 'fix', 'refactor']
info: This is a customized cz.
questions:
- type: list
Expand Down Expand Up @@ -321,6 +326,7 @@
params=[
TomlConfig(data=TOML_STR, path="not_exist.toml"),
JsonConfig(data=JSON_STR, path="not_exist.json"),
YAMLConfig(data=YAML_STR, path="not_exist.yaml"),
]
)
def config(request):
Expand Down