Skip to content

Commit 6067dc9

Browse files
Yusin0903Lee-W
authored andcommitted
test(test_changelog_command.py): add test for changelog file_name construction from args and config
1 parent 6eabcfa commit 6067dc9

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

tests/test_changelog.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import re
22
from dataclasses import dataclass
33
from pathlib import Path
4-
from typing import Any, Optional
4+
from typing import Any
5+
from unittest.mock import Mock
56

67
import pytest
78
from jinja2 import FileSystemLoader
89

910
from commitizen import changelog, git
1011
from commitizen.changelog_formats import ChangelogFormat
12+
from commitizen.commands.changelog import Changelog
13+
from commitizen.config import BaseConfig
1114
from commitizen.cz.conventional_commits.conventional_commits import (
1215
ConventionalCommitsCz,
1316
)
@@ -1499,7 +1502,7 @@ def changelog_message_builder_hook(message: dict, commit: git.GitCommit):
14991502
def test_render_changelog_with_changelog_release_hook(
15001503
gitcommits, tags, any_changelog_format: ChangelogFormat
15011504
):
1502-
def changelog_release_hook(release: dict, tag: Optional[git.GitTag]) -> dict:
1505+
def changelog_release_hook(release: dict, tag: git.GitTag | None) -> dict:
15031506
release["extra"] = "whatever"
15041507
return release
15051508

@@ -1631,3 +1634,32 @@ def test_tags_rules_get_version_tags(capsys: pytest.CaptureFixture):
16311634
captured = capsys.readouterr()
16321635
assert captured.err.count("InvalidVersion") == 2
16331636
assert captured.err.count("not-a-version") == 2
1637+
1638+
1639+
def test_changelog_file_name_from_args_and_config():
1640+
mock_config = Mock(spec=BaseConfig)
1641+
mock_config.path.parent = "/my/project/"
1642+
mock_config.settings = {
1643+
"name": "cz_conventional_commits",
1644+
"changelog_file": "CHANGELOG.md",
1645+
"encoding": "utf-8",
1646+
"changelog_start_rev": "v1.0.0",
1647+
"tag_format": "$version",
1648+
"legacy_tag_formats": [],
1649+
"ignored_tag_formats": [],
1650+
"incremental": True,
1651+
"changelog_merge_prerelease": True,
1652+
}
1653+
1654+
args = {
1655+
"file_name": "CUSTOM.md",
1656+
"incremental": None,
1657+
"dry_run": False,
1658+
"unreleased_version": "1.0.1",
1659+
}
1660+
changelog = Changelog(mock_config, args)
1661+
assert changelog.file_name == "/my/project/CUSTOM.md"
1662+
1663+
args = {"incremental": None, "dry_run": False, "unreleased_version": "1.0.1"}
1664+
changelog = Changelog(mock_config, args)
1665+
assert changelog.file_name == "/my/project/CHANGELOG.md"

0 commit comments

Comments
 (0)