Skip to content

Commit 1a7ed8d

Browse files
author
matteo_fiore
committed
test(test_changelog_command): adding test for changelog generated with customize commits
1 parent d28c095 commit 1a7ed8d

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

tests/commands/conftest.py

+31-1
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() # type: ignore
1747
def changelog_path() -> str:
1848
return os.path.join(os.getcwd(), "CHANGELOG.md")

tests/commands/test_changelog_command.py

+22
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,28 @@ def test_changelog_hook(mocker, config):
262262
changelog_hook_mock.assert_called_with(full_changelog, full_changelog)
263263

264264

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

0 commit comments

Comments
 (0)