Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 298ddb1

Browse files
committed
test(bump): refactor file loading with extracted utility function
1 parent 46a2fe8 commit 298ddb1

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

‎tests/test_bump_update_version_in_files.py‎

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from shutil import copyfile
22

33
import pytest
4+
from py._path.local import LocalPath
45

56
from commitizen import bump
67
from commitizen.exceptions import CurrentVersionNotFoundError
@@ -11,60 +12,50 @@
1112
TESTING_FILE_PREFIX = "tests/data"
1213

1314

15+
def _copy_sample_file_to_tmpdir(
16+
tmpdir: LocalPath, source_filename: str, dest_filename: str
17+
) -> str:
18+
tmp_file = tmpdir.join(dest_filename)
19+
copyfile(f"{TESTING_FILE_PREFIX}/{source_filename}", str(tmp_file))
20+
return str(tmp_file)
21+
22+
1423
@pytest.fixture(scope="function")
1524
def commitizen_config_file(tmpdir):
16-
tmp_file=tmpdir.join("pyproject.toml")
17-
copyfile(f"{TESTING_FILE_PREFIX}/sample_pyproject.toml", str(tmp_file))
18-
returnstr(tmp_file)
25+
return_copy_sample_file_to_tmpdir(
26+
tmpdir, "sample_pyproject.toml", "pyproject.toml"
27+
)
1928

2029

2130
@pytest.fixture(scope="function")
2231
def python_version_file(tmpdir, request):
23-
tmp_file = tmpdir.join("__verion__.py")
24-
copyfile(f"{TESTING_FILE_PREFIX}/sample_version.py", str(tmp_file))
25-
return str(tmp_file)
32+
return _copy_sample_file_to_tmpdir(tmpdir, "sample_version.py", "__version__.py")
2633

2734

2835
@pytest.fixture(scope="function")
2936
def inconsistent_python_version_file(tmpdir):
30-
tmp_file=tmpdir.join("__verion__.py")
31-
copyfile(f"{TESTING_FILE_PREFIX}/inconsistent_version.py", str(tmp_file))
32-
returnstr(tmp_file)
37+
return_copy_sample_file_to_tmpdir(
38+
tmpdir, "inconsistent_version.py", "__version__.py"
39+
)
3340

3441

3542
@pytest.fixture(scope="function")
3643
def random_location_version_file(tmpdir):
37-
tmp_file = tmpdir.join("Cargo.lock")
38-
copyfile(f"{TESTING_FILE_PREFIX}/sample_cargo.lock", str(tmp_file))
39-
return str(tmp_file)
44+
return _copy_sample_file_to_tmpdir(tmpdir, "sample_cargo.lock", "Cargo.lock")
4045

4146

4247
@pytest.fixture(scope="function")
4348
def version_repeated_file(tmpdir):
44-
tmp_file = tmpdir.join("package.json")
45-
copyfile(f"{TESTING_FILE_PREFIX}/repeated_version_number.json", str(tmp_file))
46-
return str(tmp_file)
47-
48-
49-
@pytest.fixture(scope="function")
50-
def multiple_versions_increase_string(tmpdir):
51-
tmp_file = tmpdir.join("anyfile")
52-
tmp_file.write(MULTIPLE_VERSIONS_INCREASE_STRING)
53-
return str(tmp_file)
54-
55-
56-
@pytest.fixture(scope="function")
57-
def multiple_versions_reduce_string(tmpdir):
58-
tmp_file = tmpdir.join("anyfile")
59-
tmp_file.write(MULTIPLE_VERSIONS_REDUCE_STRING)
60-
return str(tmp_file)
49+
return _copy_sample_file_to_tmpdir(
50+
tmpdir, "repeated_version_number.json", "package.json"
51+
)
6152

6253

6354
@pytest.fixture(scope="function")
6455
def docker_compose_file(tmpdir):
65-
tmp_file=tmpdir.join("docker-compose.yaml")
66-
copyfile(f"{TESTING_FILE_PREFIX}/sample_docker_compose.yaml", str(tmp_file))
67-
returnstr(tmp_file)
56+
return_copy_sample_file_to_tmpdir(
57+
tmpdir, "sample_docker_compose.yaml", "docker-compose.yaml"
58+
)
6859

6960

7061
@pytest.fixture(
@@ -76,10 +67,20 @@ def docker_compose_file(tmpdir):
7667
ids=("with_eol", "without_eol"),
7768
)
7869
def multiple_versions_to_update_poetry_lock(tmpdir, request):
79-
tmp_file = tmpdir.join("pyproject.toml")
80-
copyfile(
81-
f"{TESTING_FILE_PREFIX}/{request.param}", str(tmp_file),
82-
)
70+
return _copy_sample_file_to_tmpdir(tmpdir, request.param, "pyproject.toml")
71+
72+
73+
@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+
return str(tmp_file)
78+
79+
80+
@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)
8384
return str(tmp_file)
8485

8586

@@ -90,12 +91,12 @@ def version_files(
9091
version_repeated_file,
9192
docker_compose_file,
9293
):
93-
return [
94+
return (
9495
commitizen_config_file,
9596
python_version_file,
9697
version_repeated_file,
9798
docker_compose_file,
98-
]
99+
)
99100

100101

101102
def test_update_version_in_files(version_files, file_regression):

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /