Skip to content

Commit c237525

Browse files
committed
fix(changelog.py): cross-platform path handling using os.path.join and modify the path linter and test parameter
1 parent 21ebb79 commit c237525

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
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

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import os
12
import re
23
from dataclasses import dataclass
34
from pathlib import Path
4-
from unittest.mock import Mock
55
from typing import Any, Optional
6+
from unittest.mock import Mock
67

78
import pytest
89
from jinja2 import FileSystemLoader
@@ -1638,7 +1639,7 @@ def test_tags_rules_get_version_tags(capsys: pytest.CaptureFixture):
16381639

16391640
def test_changelog_file_name_from_args_and_config():
16401641
mock_config = Mock(spec=BaseConfig)
1641-
mock_config.path.parent = "/my/project/"
1642+
mock_config.path.parent = "/my/project"
16421643
mock_config.settings = {
16431644
"name": "cz_conventional_commits",
16441645
"changelog_file": "CHANGELOG.md",
@@ -1658,8 +1659,12 @@ def test_changelog_file_name_from_args_and_config():
16581659
"unreleased_version": "1.0.1",
16591660
}
16601661
changelog = Changelog(mock_config, args)
1661-
assert changelog.file_name == "/my/project/CUSTOM.md"
1662+
assert os.path.normpath(changelog.file_name) == os.path.normpath(
1663+
os.path.join("/my/project", "CUSTOM.md")
1664+
)
16621665

16631666
args = {"incremental": None, "dry_run": False, "unreleased_version": "1.0.1"}
16641667
changelog = Changelog(mock_config, args)
1665-
assert changelog.file_name == "/my/project/CHANGELOG.md"
1668+
assert os.path.normpath(changelog.file_name) == os.path.normpath(
1669+
os.path.join("/my/project", "CHANGELOG.md")
1670+
)

0 commit comments

Comments
 (0)