1
+ from __future__ import annotations
2
+
1
3
import re
2
4
from dataclasses import dataclass
3
5
from pathlib import Path
4
- from typing import Any , Optional
6
+ from typing import Any
7
+ from unittest .mock import Mock
5
8
6
9
import pytest
7
10
from jinja2 import FileSystemLoader
8
11
9
12
from commitizen import changelog , git
10
13
from commitizen .changelog_formats import ChangelogFormat
14
+ from commitizen .commands .changelog import Changelog
15
+ from commitizen .config import BaseConfig
11
16
from commitizen .cz .conventional_commits .conventional_commits import (
12
17
ConventionalCommitsCz ,
13
18
)
@@ -1499,7 +1504,7 @@ def changelog_message_builder_hook(message: dict, commit: git.GitCommit):
1499
1504
def test_render_changelog_with_changelog_release_hook (
1500
1505
gitcommits , tags , any_changelog_format : ChangelogFormat
1501
1506
):
1502
- def changelog_release_hook (release : dict , tag : Optional [ git .GitTag ] ) -> dict :
1507
+ def changelog_release_hook (release : dict , tag : git .GitTag | None ) -> dict :
1503
1508
release ["extra" ] = "whatever"
1504
1509
return release
1505
1510
@@ -1631,3 +1636,32 @@ def test_tags_rules_get_version_tags(capsys: pytest.CaptureFixture):
1631
1636
captured = capsys .readouterr ()
1632
1637
assert captured .err .count ("InvalidVersion" ) == 2
1633
1638
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