Skip to content

Commit 2bc2fa8

Browse files
Yusin0903Lee-W
authored andcommitted
fix(changelog.py): cross-platform path handling using os.path.join and modify the path linter and test parameter
1 parent 2e6f754 commit 2bc2fa8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

commitizen/commands/changelog.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
import os.path
45
from difflib import SequenceMatcher
56
from operator import itemgetter
@@ -42,7 +43,7 @@ def __init__(self, config: BaseConfig, args):
4243
f"or the setting `changelog_file` in {self.config.path}"
4344
)
4445
self.file_name = (
45-
str(Path(self.config.path.parent) / changelog_file_name)
46+
os.path.join(str(self.config.path.parent), changelog_file_name)
4647
if self.config.path is not None
4748
else changelog_file_name
4849
)

tests/test_changelog.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
import re
45
from dataclasses import dataclass
56
from pathlib import Path
@@ -1640,7 +1641,7 @@ def test_tags_rules_get_version_tags(capsys: pytest.CaptureFixture):
16401641

16411642
def test_changelog_file_name_from_args_and_config():
16421643
mock_config = Mock(spec=BaseConfig)
1643-
mock_config.path.parent = "/my/project/"
1644+
mock_config.path.parent = "/my/project"
16441645
mock_config.settings = {
16451646
"name": "cz_conventional_commits",
16461647
"changelog_file": "CHANGELOG.md",
@@ -1660,8 +1661,12 @@ def test_changelog_file_name_from_args_and_config():
16601661
"unreleased_version": "1.0.1",
16611662
}
16621663
changelog = Changelog(mock_config, args)
1663-
assert changelog.file_name == "/my/project/CUSTOM.md"
1664+
assert os.path.normpath(changelog.file_name) == os.path.normpath(
1665+
os.path.join("/my/project", "CUSTOM.md")
1666+
)
16641667

16651668
args = {"incremental": None, "dry_run": False, "unreleased_version": "1.0.1"}
16661669
changelog = Changelog(mock_config, args)
1667-
assert changelog.file_name == "/my/project/CHANGELOG.md"
1670+
assert os.path.normpath(changelog.file_name) == os.path.normpath(
1671+
os.path.join("/my/project", "CHANGELOG.md")
1672+
)

0 commit comments

Comments
 (0)