Skip to content

Commit 78d2c2d

Browse files
test: replace os.path with pathlib Path (#1835)
1 parent bc1542c commit 78d2c2d

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

tests/commands/test_commit_command.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os
1+
from pathlib import Path
22
from unittest.mock import ANY
33

44
import pytest
@@ -76,7 +76,7 @@ def test_commit_backup_on_failure(
7676

7777
prompt_mock_feat.assert_called_once()
7878
error_mock.assert_called_once()
79-
assert os.path.isfile(temp_file)
79+
assert Path(temp_file).exists()
8080

8181

8282
@pytest.mark.usefixtures("staging_is_clean", "commit_mock")
@@ -100,7 +100,7 @@ def test_commit_retry_works(
100100
commit_mock.assert_called_with("backup commit", args="")
101101
prompt_mock.assert_not_called()
102102
success_mock.assert_called_once()
103-
assert not os.path.isfile(temp_file)
103+
assert not Path(temp_file).exists()
104104

105105

106106
@pytest.mark.usefixtures("staging_is_clean")
@@ -129,7 +129,7 @@ def test_commit_retry_after_failure_works(
129129
commit_mock.assert_called_with("backup commit", args="")
130130
prompt_mock.assert_not_called()
131131
success_mock.assert_called_once()
132-
assert not os.path.isfile(temp_file)
132+
assert not Path(temp_file).exists()
133133

134134

135135
@pytest.mark.usefixtures("staging_is_clean", "backup_file")
@@ -144,7 +144,7 @@ def test_commit_retry_after_failure_with_no_retry_works(
144144
commit_mock.assert_called_with("feat: user created\n\ncloses #21", args="")
145145
prompt_mock_feat.assert_called_once()
146146
success_mock.assert_called_once()
147-
assert not os.path.isfile(temp_file)
147+
assert not Path(temp_file).exists()
148148

149149

150150
@pytest.mark.usefixtures("staging_is_clean", "prompt_mock_feat")

tests/commands/test_init_command.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import json
4-
import os
54
from pathlib import Path
65
from typing import TYPE_CHECKING, Any
76

@@ -85,12 +84,12 @@ def test_init_without_setup_pre_commit_hook(
8584
config_data = toml_file.read()
8685
assert config_data == expected_config
8786

88-
assert not os.path.isfile(pre_commit_config_filename)
87+
assert not Path(pre_commit_config_filename).exists()
8988

9089

9190
def test_init_when_config_already_exists(config: BaseConfig, capsys):
9291
# Set config path
93-
path = Path(os.sep.join(["tests", "pyproject.toml"]))
92+
path = Path("tests") / "pyproject.toml"
9493
config.path = path
9594

9695
commands.Init(config)()

tests/test_changelog.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import os
43
import re
54
from dataclasses import dataclass
65
from pathlib import Path
@@ -1672,17 +1671,16 @@ def test_changelog_file_name_from_args_and_config():
16721671

16731672
args = {
16741673
"file_name": "CUSTOM.md",
1675-
"incremental": None,
1676-
"dry_run": False,
16771674
"unreleased_version": "1.0.1",
16781675
}
16791676
changelog = Changelog(mock_config, args)
1680-
assert os.path.normpath(changelog.file_name) == os.path.normpath(
1681-
os.path.join("/my/project", "CUSTOM.md")
1677+
assert (
1678+
Path(changelog.file_name).resolve() == Path("/my/project/CUSTOM.md").resolve()
16821679
)
16831680

1684-
args = {"incremental": None, "dry_run": False, "unreleased_version": "1.0.1"}
1681+
args = {"unreleased_version": "1.0.1"}
16851682
changelog = Changelog(mock_config, args)
1686-
assert os.path.normpath(changelog.file_name) == os.path.normpath(
1687-
os.path.join("/my/project", "CHANGELOG.md")
1683+
assert (
1684+
Path(changelog.file_name).resolve()
1685+
== Path("/my/project/CHANGELOG.md").resolve()
16881686
)

0 commit comments

Comments
 (0)