Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 437d8d9

Browse files
matteo_fioreLee-W
matteo_fiore
authored andcommittedMar 29, 2022
test(test_changelog_command): adding test for changelog generated with customize commits
1 parent cc70eb6 commit 437d8d9

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed
 

‎commitizen/defaults.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pathlib
22
from collections import OrderedDict
3-
from typing import Any, Iterable, List, MutableMapping, Optional, Tuple, Union
3+
from typing import Any, Dict, Iterable, List, MutableMapping, Optional, Tuple, Union
44

55
from typing_extensions import TypedDict
66

@@ -20,6 +20,9 @@ class CzSettings(TypedDict, total=False):
2020
info_path: Union[str, pathlib.Path]
2121
info: str
2222
message_template: str
23+
commit_parser: Optional[str]
24+
changelog_pattern: Optional[str]
25+
change_type_map: Optional[Dict[str, str]]
2326

2427

2528
class Settings(TypedDict, total=False):

‎tests/commands/conftest.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from commitizen import defaults
6-
from commitizen.config import BaseConfig
6+
from commitizen.config import BaseConfig, JsonConfig
77

88

99
@pytest.fixture()
@@ -13,6 +13,36 @@ def config():
1313
return _config
1414

1515

16+
@pytest.fixture()
17+
def config_customize():
18+
json_string = r"""{
19+
"commitizen": {
20+
"name": "cz_customize",
21+
"version": "3.0.0",
22+
"changelog_incremental": "true",
23+
"customize": {
24+
"message_template": "{{prefix}}({{scope}}): {{subject}}\n\n{{body}}{% if is_breaking_change %}\nBREAKING CHANGE: {{footer}}{% endif %}",
25+
"schema": "<type>(<scope>): <subject>\n<BLANK LINE>\n<body>\n<BLANK LINE>\n(BREAKING CHANGE: <footer>)",
26+
"schema_pattern": "(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)(\\(\\S+\\))?!?:(\\s.*)",
27+
"change_type_map": {
28+
"feat": "Feat",
29+
"fix": "Fix",
30+
"refactor": "Refactor",
31+
"perf": "Perf"
32+
},
33+
"change_type_order": ["Refactor", "Feat"],
34+
"commit_parser": "^(?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE)(?:\\((?P<scope>[^()\\r\\n]*)\\)|\\()?(?P<breaking>!)?:\\s(?P<message>.*)?",
35+
"changelog_pattern": "^(BREAKING[\\-\\ ]CHANGE|feat|fix|refactor|perf)(\\(.+\\))?(!)?",
36+
"questions": [
37+
38+
]
39+
}
40+
}
41+
}"""
42+
_config = JsonConfig(data=json_string, path="not_exist.json")
43+
return _config
44+
45+
1646
@pytest.fixture()
1747
def changelog_path() -> str:
1848
return os.path.join(os.getcwd(), "CHANGELOG.md")

‎tests/commands/test_changelog_command.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,28 @@ def test_changelog_hook(mocker, config):
263263
changelog_hook_mock.assert_called_with(full_changelog, full_changelog)
264264

265265

266+
@pytest.mark.usefixtures("tmp_commitizen_project")
267+
def test_changelog_hook_customize(mocker, config_customize):
268+
changelog_hook_mock = mocker.Mock()
269+
changelog_hook_mock.return_value = "cool changelog hook"
270+
271+
create_file_and_commit("feat: new file")
272+
create_file_and_commit("refactor: is in changelog")
273+
create_file_and_commit("Merge into master")
274+
275+
changelog = Changelog(
276+
config_customize,
277+
{"unreleased_version": None, "incremental": True, "dry_run": False},
278+
)
279+
mocker.patch.object(changelog.cz, "changelog_hook", changelog_hook_mock)
280+
changelog()
281+
full_changelog = (
282+
"## Unreleased\n\n### Refactor\n\n- is in changelog\n\n### Feat\n\n- new file\n"
283+
)
284+
285+
changelog_hook_mock.assert_called_with(full_changelog, full_changelog)
286+
287+
266288
@pytest.mark.usefixtures("tmp_commitizen_project")
267289
def test_changelog_multiple_incremental_do_not_add_new_lines(
268290
mocker, capsys, changelog_path

0 commit comments

Comments
 (0)
Please sign in to comment.