Skip to content

Commit 15c1857

Browse files
Yusin0903Lee-W
authored andcommitted
test(test_changelog_command.py): add test for changelog file_name construction from args and config
1 parent 776d70f commit 15c1857

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

tests/test_changelog.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
from __future__ import annotations
2+
13
import re
24
from dataclasses import dataclass
35
from pathlib import Path
4-
from typing import Any, Optional
6+
from typing import Any
7+
from unittest.mock import Mock
58

69
import pytest
710
from jinja2 import FileSystemLoader
811

912
from commitizen import changelog, git
1013
from commitizen.changelog_formats import ChangelogFormat
14+
from commitizen.commands.changelog import Changelog
15+
from commitizen.config import BaseConfig
1116
from commitizen.cz.conventional_commits.conventional_commits import (
1217
ConventionalCommitsCz,
1318
)
@@ -1499,7 +1504,7 @@ def changelog_message_builder_hook(message: dict, commit: git.GitCommit):
14991504
def test_render_changelog_with_changelog_release_hook(
15001505
gitcommits, tags, any_changelog_format: ChangelogFormat
15011506
):
1502-
def changelog_release_hook(release: dict, tag: Optional[git.GitTag]) -> dict:
1507+
def changelog_release_hook(release: dict, tag: git.GitTag | None) -> dict:
15031508
release["extra"] = "whatever"
15041509
return release
15051510

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

0 commit comments

Comments
 (0)