66import pytest
77
88from cppython .plugins .conan .builder import Builder
9- from cppython .plugins .conan .schema import ConanDependency , ConanVersion
9+ from cppython .plugins .conan .schema import ConanDependency , ConanfileGenerationData , ConanVersion
1010
1111
1212class TestBuilder :
@@ -44,13 +44,16 @@ def test_creates_both_files(self, builder: Builder, tmp_path: Path) -> None:
4444 ]
4545 dependency_groups = {}
4646
47- builder .generate_conanfile (
48- directory = tmp_path ,
47+ data = ConanfileGenerationData (
4948 dependencies = dependencies ,
5049 dependency_groups = dependency_groups ,
5150 name = 'test-project' ,
5251 version = '1.0.0' ,
5352 )
53+ builder .generate_conanfile (
54+ directory = tmp_path ,
55+ data = data ,
56+ )
5457
5558 base_file = tmp_path / 'conanfile_base.py'
5659 conan_file = tmp_path / 'conanfile.py'
@@ -60,37 +63,43 @@ def test_creates_both_files(self, builder: Builder, tmp_path: Path) -> None:
6063
6164 def test_regenerates_base_file (self , builder : Builder , tmp_path : Path ) -> None :
6265 """Test base file is always regenerated with new dependencies."""
63- dependencies_v1 = [
66+ initial_dependencies = [
6467 ConanDependency (name = 'boost' , version = ConanVersion .from_string ('1.80.0' )),
6568 ]
6669
67- builder .generate_conanfile (
68- directory = tmp_path ,
69- dependencies = dependencies_v1 ,
70+ initial_data = ConanfileGenerationData (
71+ dependencies = initial_dependencies ,
7072 dependency_groups = {},
7173 name = 'test-project' ,
7274 version = '1.0.0' ,
7375 )
76+ builder .generate_conanfile (
77+ directory = tmp_path ,
78+ data = initial_data ,
79+ )
7480
7581 base_file = tmp_path / 'conanfile_base.py'
76- content_v1 = base_file .read_text (encoding = 'utf-8' )
77- assert 'boost/1.80.0' in content_v1
82+ initial_content = base_file .read_text (encoding = 'utf-8' )
83+ assert 'boost/1.80.0' in initial_content
7884
79- dependencies_v2 = [
85+ updated_dependencies = [
8086 ConanDependency (name = 'zlib' , version = ConanVersion .from_string ('1.2.13' )),
8187 ]
8288
83- builder .generate_conanfile (
84- directory = tmp_path ,
85- dependencies = dependencies_v2 ,
89+ updated_data = ConanfileGenerationData (
90+ dependencies = updated_dependencies ,
8691 dependency_groups = {},
8792 name = 'test-project' ,
8893 version = '1.0.0' ,
8994 )
95+ builder .generate_conanfile (
96+ directory = tmp_path ,
97+ data = updated_data ,
98+ )
9099
91- content_v2 = base_file .read_text (encoding = 'utf-8' )
92- assert 'zlib/1.2.13' in content_v2
93- assert 'boost/1.80.0' not in content_v2
100+ updated_content = base_file .read_text (encoding = 'utf-8' )
101+ assert 'zlib/1.2.13' in updated_content
102+ assert 'boost/1.80.0' not in updated_content
94103
95104 def test_preserves_user_file (self , builder : Builder , tmp_path : Path ) -> None :
96105 """Test user conanfile is never modified once created."""
@@ -112,13 +121,16 @@ def requirements(self):
112121 ConanDependency (name = 'boost' , version = ConanVersion .from_string ('1.80.0' )),
113122 ]
114123
115- builder .generate_conanfile (
116- directory = tmp_path ,
124+ data = ConanfileGenerationData (
117125 dependencies = dependencies ,
118126 dependency_groups = {},
119127 name = 'new-name' ,
120128 version = '2.0.0' ,
121129 )
130+ builder .generate_conanfile (
131+ directory = tmp_path ,
132+ data = data ,
133+ )
122134
123135 final_content = conan_file .read_text ()
124136 assert final_content == custom_content
@@ -137,13 +149,16 @@ def test_inheritance_chain(self, builder: Builder, tmp_path: Path) -> None:
137149 ]
138150 }
139151
140- builder .generate_conanfile (
141- directory = tmp_path ,
152+ data = ConanfileGenerationData (
142153 dependencies = dependencies ,
143154 dependency_groups = dependency_groups ,
144155 name = 'test-project' ,
145156 version = '1.0.0' ,
146157 )
158+ builder .generate_conanfile (
159+ directory = tmp_path ,
160+ data = data ,
161+ )
147162
148163 base_content = (tmp_path / 'conanfile_base.py' ).read_text (encoding = 'utf-8' )
149164 user_content = (tmp_path / 'conanfile.py' ).read_text (encoding = 'utf-8' )
@@ -156,3 +171,55 @@ def test_inheritance_chain(self, builder: Builder, tmp_path: Path) -> None:
156171 assert 'class TestProjectPackage(CPPythonBase):' in user_content
157172 assert 'super().requirements()' in user_content
158173 assert 'super().build_requirements()' in user_content
174+
175+ def test_cmake_binary_configure (self , builder : Builder , tmp_path : Path ) -> None :
176+ """Test that cmake_binary generates configure() with forward slashes."""
177+ base_file = tmp_path / 'conanfile_base.py'
178+ cmake_path = Path ('C:/Program Files/CMake/bin/cmake.exe' )
179+
180+ builder ._create_base_conanfile (base_file , [], {}, cmake_binary = cmake_path )
181+
182+ content = base_file .read_text (encoding = 'utf-8' )
183+ assert 'def configure(self):' in content
184+ assert 'self.conf.define("tools.cmake:cmake_program"' in content
185+ assert 'C:/Program Files/CMake/bin/cmake.exe' in content
186+ assert '\\ ' not in content .split ('tools.cmake:cmake_program' )[1 ].split ('"' )[1 ]
187+
188+ def test_no_cmake_binary (self , builder : Builder , tmp_path : Path ) -> None :
189+ """Test that no cmake_binary means no configure() method."""
190+ base_file = tmp_path / 'conanfile_base.py'
191+
192+ builder ._create_base_conanfile (base_file , [], {}, cmake_binary = None )
193+
194+ content = base_file .read_text (encoding = 'utf-8' )
195+ assert 'def configure(self):' not in content
196+
197+ @pytest .mark .parametrize (
198+ ('venv_cmake' , 'expect_configure' ),
199+ [
200+ ('/path/to/venv/bin/cmake' , True ),
201+ (None , False ),
202+ ],
203+ )
204+ def test_cmake_binary_venv_fallback (
205+ self ,
206+ builder : Builder ,
207+ tmp_path : Path ,
208+ monkeypatch : pytest .MonkeyPatch ,
209+ venv_cmake : str | None ,
210+ expect_configure : bool ,
211+ ) -> None :
212+ """Test venv cmake fallback when cmake_binary is default."""
213+ monkeypatch .setattr ('cppython.plugins.conan.builder.shutil.which' , lambda _ : venv_cmake )
214+
215+ data = ConanfileGenerationData (
216+ dependencies = [],
217+ dependency_groups = {},
218+ name = 'test-project' ,
219+ version = '1.0.0' ,
220+ cmake_binary = 'cmake' ,
221+ )
222+ builder .generate_conanfile (directory = tmp_path , data = data )
223+
224+ content = (tmp_path / 'conanfile_base.py' ).read_text (encoding = 'utf-8' )
225+ assert ('def configure(self):' in content ) == expect_configure
0 commit comments