Skip to content

Commit e63600b

Browse files
committed
test: replace tmpdir with tmppath
1 parent 1831c3c commit e63600b

File tree

1 file changed

+42
-37
lines changed

1 file changed

+42
-37
lines changed

tests/test_bump_update_version_in_files.py

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from shutil import copyfile
33

44
import pytest
5+
from _pytest.fixtures import FixtureRequest
56

67
from commitizen import bump
78
from commitizen.exceptions import CurrentVersionNotFoundError
@@ -21,40 +22,40 @@ def _copy_sample_file_to_tmpdir(
2122

2223

2324
@pytest.fixture(scope="function")
24-
def commitizen_config_file(tmpdir):
25+
def commitizen_config_file(tmp_path: Path) -> Path:
2526
return _copy_sample_file_to_tmpdir(
26-
tmpdir, "sample_pyproject.toml", "pyproject.toml"
27+
tmp_path, "sample_pyproject.toml", "pyproject.toml"
2728
)
2829

2930

3031
@pytest.fixture(scope="function")
31-
def python_version_file(tmpdir, request):
32-
return _copy_sample_file_to_tmpdir(tmpdir, "sample_version.py", "__version__.py")
32+
def python_version_file(tmp_path: Path, request: FixtureRequest) -> Path:
33+
return _copy_sample_file_to_tmpdir(tmp_path, "sample_version.py", "__version__.py")
3334

3435

3536
@pytest.fixture(scope="function")
36-
def inconsistent_python_version_file(tmpdir):
37+
def inconsistent_python_version_file(tmp_path: Path) -> Path:
3738
return _copy_sample_file_to_tmpdir(
38-
tmpdir, "inconsistent_version.py", "__version__.py"
39+
tmp_path, "inconsistent_version.py", "__version__.py"
3940
)
4041

4142

4243
@pytest.fixture(scope="function")
43-
def random_location_version_file(tmpdir):
44-
return _copy_sample_file_to_tmpdir(tmpdir, "sample_cargo.lock", "Cargo.lock")
44+
def random_location_version_file(tmp_path: Path) -> Path:
45+
return _copy_sample_file_to_tmpdir(tmp_path, "sample_cargo.lock", "Cargo.lock")
4546

4647

4748
@pytest.fixture(scope="function")
48-
def version_repeated_file(tmpdir):
49+
def version_repeated_file(tmp_path: Path) -> Path:
4950
return _copy_sample_file_to_tmpdir(
50-
tmpdir, "repeated_version_number.json", "package.json"
51+
tmp_path, "repeated_version_number.json", "package.json"
5152
)
5253

5354

5455
@pytest.fixture(scope="function")
55-
def docker_compose_file(tmpdir):
56+
def docker_compose_file(tmp_path: Path) -> Path:
5657
return _copy_sample_file_to_tmpdir(
57-
tmpdir, "sample_docker_compose.yaml", "docker-compose.yaml"
58+
tmp_path, "sample_docker_compose.yaml", "docker-compose.yaml"
5859
)
5960

6061

@@ -66,36 +67,38 @@ def docker_compose_file(tmpdir):
6667
),
6768
ids=("with_eol", "without_eol"),
6869
)
69-
def multiple_versions_to_update_poetry_lock(tmpdir, request):
70-
return _copy_sample_file_to_tmpdir(tmpdir, request.param, "pyproject.toml")
70+
def multiple_versions_to_update_poetry_lock(
71+
tmp_path: Path, request: FixtureRequest
72+
) -> Path:
73+
return _copy_sample_file_to_tmpdir(tmp_path, request.param, "pyproject.toml")
7174

7275

7376
@pytest.fixture(scope="function")
74-
def multiple_versions_increase_string(tmpdir):
75-
tmp_file = tmpdir.join("anyfile")
76-
tmp_file.write(MULTIPLE_VERSIONS_INCREASE_STRING)
77+
def multiple_versions_increase_string(tmp_path: Path) -> str:
78+
tmp_file = tmp_path / "anyfile"
79+
tmp_file.write_text(MULTIPLE_VERSIONS_INCREASE_STRING)
7780
return str(tmp_file)
7881

7982

8083
@pytest.fixture(scope="function")
81-
def multiple_versions_reduce_string(tmpdir):
82-
tmp_file = tmpdir.join("anyfile")
83-
tmp_file.write(MULTIPLE_VERSIONS_REDUCE_STRING)
84+
def multiple_versions_reduce_string(tmp_path: Path) -> str:
85+
tmp_file = tmp_path / "anyfile"
86+
tmp_file.write_text(MULTIPLE_VERSIONS_REDUCE_STRING)
8487
return str(tmp_file)
8588

8689

8790
@pytest.fixture(scope="function")
8891
def version_files(
89-
commitizen_config_file,
90-
python_version_file,
91-
version_repeated_file,
92-
docker_compose_file,
93-
):
92+
commitizen_config_file: Path,
93+
python_version_file: Path,
94+
version_repeated_file: Path,
95+
docker_compose_file: Path,
96+
) -> tuple[str, ...]:
9497
return (
95-
commitizen_config_file,
96-
python_version_file,
97-
version_repeated_file,
98-
docker_compose_file,
98+
str(commitizen_config_file),
99+
str(python_version_file),
100+
str(version_repeated_file),
101+
str(docker_compose_file),
99102
)
100103

101104

@@ -228,12 +231,14 @@ def test_multiple_versions_to_bump(
228231
def test_update_version_in_globbed_files(commitizen_config_file, file_regression):
229232
old_version = "1.2.3"
230233
new_version = "2.0.0"
231-
other = commitizen_config_file.dirpath("other.toml")
232-
print(commitizen_config_file, other)
234+
other = commitizen_config_file.parent / "other.toml"
235+
233236
copyfile(commitizen_config_file, other)
234237

235238
# Prepend full path as test assume absolute paths or cwd-relative
236-
version_files = [commitizen_config_file.dirpath("*.toml")]
239+
version_files = [
240+
str(file_path) for file_path in commitizen_config_file.parent.glob("*.toml")
241+
]
237242

238243
bump.update_version_in_files(
239244
old_version,
@@ -247,13 +252,15 @@ def test_update_version_in_globbed_files(commitizen_config_file, file_regression
247252
file_regression.check(file.read_text("utf-8"), extension=".toml")
248253

249254

250-
def test_update_version_in_files_with_check_consistency_true(version_files):
255+
def test_update_version_in_files_with_check_consistency_true(
256+
version_files: tuple[str, ...],
257+
):
251258
"""Test update_version_in_files with check_consistency=True (success case)."""
252259
old_version = "1.2.3"
253260
new_version = "2.0.0"
254261

255262
# This should succeed because all files contain the current version
256-
updated_files = bump.update_version_in_files(
263+
updated_files: list[str] = bump.update_version_in_files(
257264
old_version,
258265
new_version,
259266
version_files,
@@ -262,9 +269,7 @@ def test_update_version_in_files_with_check_consistency_true(version_files):
262269
)
263270

264271
# Verify that all files were updated
265-
assert len(updated_files) == len(version_files)
266-
for file_path in updated_files:
267-
assert file_path in version_files
272+
assert set(updated_files) == set(version_files)
268273

269274

270275
def test_update_version_in_files_with_check_consistency_true_failure(

0 commit comments

Comments
 (0)