@@ -136,210 +136,7 @@ def mock_resolve(requirement: Requirement) -> ConanDependency:
136136 # Verify Conan API was attempted
137137 mock_conan_api_constructor .assert_called_once ()
138138
139- def test_install_with_profile_exception_fallback (
140- self ,
141- plugin : ConanProvider ,
142- conan_temp_conanfile : Path ,
143- conan_mock_dependencies : list [Requirement ],
144- conan_setup_mocks : dict [str , Mock ],
145- conan_mock_api : Mock ,
146- ) -> None :
147- """Test install method when profile operations throw exceptions
148-
149- Args:
150- plugin: The plugin instance
151- conan_temp_conanfile: Path to temporary conanfile.py
152- conan_mock_dependencies: List of mock dependencies
153- conan_setup_mocks: Dictionary containing all mocks
154- conan_mock_api: Mock ConanAPI instance
155- """
156- # Configure the API mock to throw exception on first profile call
157- conan_mock_api .profiles .get_default_host .side_effect = Exception ('Profile not found' )
158-
159- # Setup dependencies
160- plugin .core_data .cppython_data .dependencies = conan_mock_dependencies
161-
162- # Execute - should not throw an exception despite profile operations failing
163- plugin .install ()
164-
165- # Verify that despite the exceptions, the fallback was used
166- conan_setup_mocks ['conan_api_constructor' ].assert_called_once ()
167- conan_mock_api .profiles .get_default_host .assert_called_once ()
168- # Note: get_default_build is not called because get_default_host throws exception first
169-
170- # Verify fallback profile creation was called (should be called twice for detect)
171- assert conan_mock_api .profiles .detect .call_count >= EXPECTED_PROFILE_CALLS
172-
173- # Verify the rest of the process continued
174- conan_mock_api .graph .load_graph_consumer .assert_called_once ()
175- conan_mock_api .install .install_binaries .assert_called_once ()
176- conan_mock_api .install .install_consumer .assert_called_once ()
177-
178- def test_publish_with_profile_exception_fallback (
179- self ,
180- plugin : ConanProvider ,
181- conan_temp_conanfile : Path ,
182- conan_mock_api_publish : Mock ,
183- mocker : MockerFixture ,
184- ) -> None :
185- """Test publish method when profile operations throw exceptions
186-
187- Args:
188- plugin: The plugin instance
189- conan_temp_conanfile: Path to temporary conanfile.py
190- conan_mock_api_publish: Mock ConanAPI instance configured for publish
191- mocker: Pytest mocker fixture
192- """
193- # Set plugin to local mode to avoid remote upload complications
194- plugin .data = plugin .data .__class__ (
195- remotes = [],
196- )
197-
198- # Configure the API mock to throw exception on first profile call
199- conan_mock_api_publish .profiles .get_default_host .side_effect = Exception ('Profile configuration error' )
200-
201- # Mock ConanAPI constructor to return our configured mock
202- mock_conan_api_constructor = mocker .patch (
203- 'cppython.plugins.conan.plugin.ConanAPI' , return_value = conan_mock_api_publish
204- )
205-
206- # Execute - should not throw an exception despite profile operations failing
207- plugin .publish ()
208-
209- # Verify that despite the exceptions, the fallback was used
210- mock_conan_api_constructor .assert_called_once ()
211- conan_mock_api_publish .profiles .get_default_host .assert_called_once ()
212- # Note: get_default_build is not called because get_default_host throws exception first
213-
214- # Verify fallback profile creation was called (should be called twice for detect)
215- assert conan_mock_api_publish .profiles .detect .call_count >= EXPECTED_PROFILE_CALLS
216-
217- # Verify the rest of the process continued
218- conan_mock_api_publish .export .export .assert_called_once ()
219- conan_mock_api_publish .graph .load_graph_consumer .assert_called_once ()
220- conan_mock_api_publish .install .install_binaries .assert_called_once ()
221-
222- def test_install_with_second_profile_exception_fallback (
223- self ,
224- plugin : ConanProvider ,
225- conan_temp_conanfile : Path ,
226- conan_mock_dependencies : list [Requirement ],
227- conan_setup_mocks : dict [str , Mock ],
228- conan_mock_api : Mock ,
229- ) -> None :
230- """Test install method when the second profile operation throws exception
231-
232- Args:
233- plugin: The plugin instance
234- conan_temp_conanfile: Path to temporary conanfile.py
235- conan_mock_dependencies: List of mock dependencies
236- conan_setup_mocks: Dictionary containing all mocks
237- conan_mock_api: Mock ConanAPI instance
238- """
239- # Configure the API mock: first call succeeds, second one fails
240- conan_mock_api .profiles .get_default_host .return_value = '/path/to/host'
241- conan_mock_api .profiles .get_default_build .side_effect = Exception ('Build profile not found' )
242-
243- # Setup dependencies
244- plugin .core_data .cppython_data .dependencies = conan_mock_dependencies
245-
246- # Execute - should not throw an exception despite profile operations failing
247- plugin .install ()
248-
249- # Verify that despite the exceptions, the fallback was used
250- conan_setup_mocks ['conan_api_constructor' ].assert_called_once ()
251- conan_mock_api .profiles .get_default_host .assert_called_once ()
252- conan_mock_api .profiles .get_default_build .assert_called_once ()
253-
254- # Verify fallback profile creation was called (should be called twice for detect)
255- assert conan_mock_api .profiles .detect .call_count >= EXPECTED_PROFILE_CALLS
256-
257- # Verify the rest of the process continued
258- conan_mock_api .graph .load_graph_consumer .assert_called_once ()
259- conan_mock_api .install .install_binaries .assert_called_once ()
260- conan_mock_api .install .install_consumer .assert_called_once ()
261-
262- def test_install_with_get_profile_returning_none_fallback (
263- self ,
264- plugin : ConanProvider ,
265- conan_temp_conanfile : Path ,
266- conan_mock_dependencies : list [Requirement ],
267- conan_setup_mocks : dict [str , Mock ],
268- conan_mock_api : Mock ,
269- ) -> None :
270- """Test install method when get_profile returns None (profile file corrupted/invalid)
271-
272- Args:
273- plugin: The plugin instance
274- conan_temp_conanfile: Path to temporary conanfile.py
275- conan_mock_dependencies: List of mock dependencies
276- conan_setup_mocks: Dictionary containing all mocks
277- conan_mock_api: Mock ConanAPI instance
278- """
279- # Configure profiles to exist but get_profile returns None (corrupted/invalid profile)
280- conan_mock_api .profiles .get_default_host .return_value = '/path/to/host/profile'
281- conan_mock_api .profiles .get_default_build .return_value = '/path/to/build/profile'
282- conan_mock_api .profiles .get_profile .return_value = None # Profile file exists but is corrupted
283-
284- # Setup dependencies
285- plugin .core_data .cppython_data .dependencies = conan_mock_dependencies
286-
287- # Execute - should not throw an exception despite get_profile returning None
288- plugin .install ()
289-
290- # Verify that despite get_profile returning None, the fallback was used
291- conan_setup_mocks ['conan_api_constructor' ].assert_called_once ()
292- conan_mock_api .profiles .get_default_host .assert_called_once ()
293- conan_mock_api .profiles .get_default_build .assert_called_once ()
294-
295- # Should call get_profile twice (once for host, once for build)
296- assert conan_mock_api .profiles .get_profile .call_count == EXPECTED_GET_PROFILE_CALLS
297-
298- # Verify fallback profile creation was called (should be called twice for detect)
299- assert conan_mock_api .profiles .detect .call_count >= EXPECTED_PROFILE_CALLS
300-
301- # Verify the rest of the process continued
302- conan_mock_api .graph .load_graph_consumer .assert_called_once ()
303- conan_mock_api .install .install_binaries .assert_called_once ()
304- conan_mock_api .install .install_consumer .assert_called_once ()
305-
306- def test_install_with_detect_returning_none_graceful_handling (
307- self ,
308- plugin : ConanProvider ,
309- conan_temp_conanfile : Path ,
310- conan_mock_dependencies : list [Requirement ],
311- conan_setup_mocks : dict [str , Mock ],
312- conan_mock_api : Mock ,
313- ) -> None :
314- """Test install method when detect() returns None (graceful handling)
315-
316- Args:
317- plugin: The plugin instance
318- conan_temp_conanfile: Path to temporary conanfile.py
319- conan_mock_dependencies: List of mock dependencies
320- conan_setup_mocks: Dictionary containing all mocks
321- conan_mock_api: Mock ConanAPI instance
322- """
323- # Configure profiles to not exist and detect to return None
324- conan_mock_api .profiles .get_default_host .return_value = None
325- conan_mock_api .profiles .get_default_build .return_value = None
326- conan_mock_api .profiles .detect .return_value = None # This should be handled gracefully
327-
328- # Setup dependencies
329- plugin .core_data .cppython_data .dependencies = conan_mock_dependencies
330-
331- # Execute - should succeed gracefully by letting Conan handle None profiles
332- plugin .install ()
333-
334- # Verify that detect was called (fallback was attempted)
335- conan_mock_api .profiles .detect .assert_called ()
336-
337- # Verify the rest of the process continued (profiles were omitted from API call)
338- conan_mock_api .graph .load_graph_consumer .assert_called_once ()
339- conan_mock_api .install .install_binaries .assert_called_once ()
340- conan_mock_api .install .install_consumer .assert_called_once ()
341-
342- def test_install_with_profile_exception_fallback_to_detect_works (
139+ def test_install_with_profile_exception (
343140 self ,
344141 plugin : ConanProvider ,
345142 conan_temp_conanfile : Path ,
0 commit comments