From db52ea80a91d71ba58a25e458c0703fd738c5793 Mon Sep 17 00:00:00 2001 From: Yu-Ting Hsiung Date: Sun, 1 Feb 2026 19:53:58 +0800 Subject: [PATCH] test: replace os.path with pathlib Path --- tests/commands/test_commit_command.py | 10 +++++----- tests/commands/test_init_command.py | 5 ++--- tests/test_changelog.py | 14 ++++++-------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/tests/commands/test_commit_command.py b/tests/commands/test_commit_command.py index 89a9224b8..c80a13823 100644 --- a/tests/commands/test_commit_command.py +++ b/tests/commands/test_commit_command.py @@ -1,4 +1,4 @@ -import os +from pathlib import Path from unittest.mock import ANY import pytest @@ -76,7 +76,7 @@ def test_commit_backup_on_failure( prompt_mock_feat.assert_called_once() error_mock.assert_called_once() - assert os.path.isfile(temp_file) + assert Path(temp_file).exists() @pytest.mark.usefixtures("staging_is_clean", "commit_mock") @@ -100,7 +100,7 @@ def test_commit_retry_works( commit_mock.assert_called_with("backup commit", args="") prompt_mock.assert_not_called() success_mock.assert_called_once() - assert not os.path.isfile(temp_file) + assert not Path(temp_file).exists() @pytest.mark.usefixtures("staging_is_clean") @@ -129,7 +129,7 @@ def test_commit_retry_after_failure_works( commit_mock.assert_called_with("backup commit", args="") prompt_mock.assert_not_called() success_mock.assert_called_once() - assert not os.path.isfile(temp_file) + assert not Path(temp_file).exists() @pytest.mark.usefixtures("staging_is_clean", "backup_file") @@ -144,7 +144,7 @@ def test_commit_retry_after_failure_with_no_retry_works( commit_mock.assert_called_with("feat: user created\n\ncloses #21", args="") prompt_mock_feat.assert_called_once() success_mock.assert_called_once() - assert not os.path.isfile(temp_file) + assert not Path(temp_file).exists() @pytest.mark.usefixtures("staging_is_clean", "prompt_mock_feat") diff --git a/tests/commands/test_init_command.py b/tests/commands/test_init_command.py index 0cf6377ea..ad4431bfd 100644 --- a/tests/commands/test_init_command.py +++ b/tests/commands/test_init_command.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -import os from pathlib import Path from typing import TYPE_CHECKING, Any @@ -85,12 +84,12 @@ def test_init_without_setup_pre_commit_hook( config_data = toml_file.read() assert config_data == expected_config - assert not os.path.isfile(pre_commit_config_filename) + assert not Path(pre_commit_config_filename).exists() def test_init_when_config_already_exists(config: BaseConfig, capsys): # Set config path - path = Path(os.sep.join(["tests", "pyproject.toml"])) + path = Path("tests") / "pyproject.toml" config.path = path commands.Init(config)() diff --git a/tests/test_changelog.py b/tests/test_changelog.py index 0831bcc1f..33fa6f6e0 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -1,6 +1,5 @@ from __future__ import annotations -import os import re from dataclasses import dataclass from pathlib import Path @@ -1672,17 +1671,16 @@ def test_changelog_file_name_from_args_and_config(): args = { "file_name": "CUSTOM.md", - "incremental": None, - "dry_run": False, "unreleased_version": "1.0.1", } changelog = Changelog(mock_config, args) - assert os.path.normpath(changelog.file_name) == os.path.normpath( - os.path.join("/my/project", "CUSTOM.md") + assert ( + Path(changelog.file_name).resolve() == Path("/my/project/CUSTOM.md").resolve() ) - args = {"incremental": None, "dry_run": False, "unreleased_version": "1.0.1"} + args = {"unreleased_version": "1.0.1"} changelog = Changelog(mock_config, args) - assert os.path.normpath(changelog.file_name) == os.path.normpath( - os.path.join("/my/project", "CHANGELOG.md") + assert ( + Path(changelog.file_name).resolve() + == Path("/my/project/CHANGELOG.md").resolve() )