1+ from collections .abc import Callable
12from pathlib import Path
23from shutil import copyfile
4+ from typing import TypeAlias
35
46import pytest
57from _pytest .fixtures import FixtureRequest
1012MULTIPLE_VERSIONS_INCREASE_STRING = 'version = "1.2.9"\n ' * 30
1113MULTIPLE_VERSIONS_REDUCE_STRING = 'version = "1.2.10"\n ' * 30
1214
13- TESTING_FILE_PREFIX = "tests/data"
1415
16+ SampleFileFixture : TypeAlias = Callable [[str , str ], Path ]
1517
16- def _copy_sample_file_to_tmpdir (
17- tmp_path : Path , source_filename : str , dest_filename : str
18- ) -> Path :
19- tmp_file = tmp_path / dest_filename
20- copyfile (f"{ TESTING_FILE_PREFIX } /{ source_filename } " , tmp_file )
21- return tmp_file
18+
19+ @pytest .fixture
20+ def sample_file (tmp_path : Path , data_dir : Path ) -> SampleFileFixture :
21+ def fixture (source : str , destination : str ) -> Path :
22+ tmp_file = tmp_path / destination
23+ copyfile (data_dir / source , tmp_file )
24+ return tmp_file
25+
26+ return fixture
2227
2328
2429@pytest .fixture (scope = "function" )
25- def commitizen_config_file (tmp_path : Path ) -> Path :
26- return _copy_sample_file_to_tmpdir (
27- tmp_path , "sample_pyproject.toml" , "pyproject.toml"
28- )
30+ def commitizen_config_file (sample_file : SampleFileFixture ) -> Path :
31+ return sample_file ("sample_pyproject.toml" , "pyproject.toml" )
2932
3033
3134@pytest .fixture (scope = "function" )
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" )
35+ def python_version_file (sample_file : SampleFileFixture ) -> Path :
36+ return sample_file ( "sample_version.py" , "__version__.py" )
3437
3538
3639@pytest .fixture (scope = "function" )
37- def inconsistent_python_version_file (tmp_path : Path ) -> Path :
38- return _copy_sample_file_to_tmpdir (
39- tmp_path , "inconsistent_version.py" , "__version__.py"
40- )
40+ def inconsistent_python_version_file (sample_file : SampleFileFixture ) -> Path :
41+ return sample_file ("inconsistent_version.py" , "__version__.py" )
4142
4243
4344@pytest .fixture (scope = "function" )
44- def random_location_version_file (tmp_path : Path ) -> Path :
45- return _copy_sample_file_to_tmpdir ( tmp_path , "sample_cargo.lock" , "Cargo.lock" )
45+ def random_location_version_file (sample_file : SampleFileFixture ) -> Path :
46+ return sample_file ( "sample_cargo.lock" , "Cargo.lock" )
4647
4748
4849@pytest .fixture (scope = "function" )
49- def version_repeated_file (tmp_path : Path ) -> Path :
50- return _copy_sample_file_to_tmpdir (
51- tmp_path , "repeated_version_number.json" , "package.json"
52- )
50+ def version_repeated_file (sample_file : SampleFileFixture ) -> Path :
51+ return sample_file ("repeated_version_number.json" , "package.json" )
5352
5453
5554@pytest .fixture (scope = "function" )
56- def docker_compose_file (tmp_path : Path ) -> Path :
57- return _copy_sample_file_to_tmpdir (
58- tmp_path , "sample_docker_compose.yaml" , "docker-compose.yaml"
59- )
55+ def docker_compose_file (sample_file : SampleFileFixture ) -> Path :
56+ return sample_file ("sample_docker_compose.yaml" , "docker-compose.yaml" )
6057
6158
6259@pytest .fixture (
@@ -68,9 +65,9 @@ def docker_compose_file(tmp_path: Path) -> Path:
6865 ids = ("with_eol" , "without_eol" ),
6966)
7067def multiple_versions_to_update_poetry_lock (
71- tmp_path : Path , request : FixtureRequest
68+ sample_file : SampleFileFixture , request : FixtureRequest
7269) -> Path :
73- return _copy_sample_file_to_tmpdir ( tmp_path , request .param , "pyproject.toml" )
70+ return sample_file ( request .param , "pyproject.toml" )
7471
7572
7673@pytest .fixture (scope = "function" )
0 commit comments