Skip to content

Commit 46ae7ea

Browse files
committed
Clean Tests
1 parent e9f4620 commit 46ae7ea

File tree

3 files changed

+19
-252
lines changed

3 files changed

+19
-252
lines changed

tests/integration/plugins/conan/test_provider.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Integration tests for the provider"""
22

3+
from pathlib import Path
34
from typing import Any
45

56
import pytest
@@ -8,6 +9,23 @@
89
from cppython.test.pytest.contracts import ProviderIntegrationTestContract
910

1011

12+
@pytest.fixture(autouse=True)
13+
def clean_conan_cache(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
14+
"""Sets CONAN_HOME to a temporary directory for each test.
15+
16+
This ensures all tests run with a clean Conan cache.
17+
18+
Args:
19+
tmp_path: Pytest temporary directory fixture
20+
monkeypatch: Pytest monkeypatch fixture for environment variable manipulation
21+
"""
22+
conan_home = tmp_path / 'conan_home'
23+
conan_home.mkdir()
24+
25+
# Set CONAN_HOME to the temporary directory
26+
monkeypatch.setenv('CONAN_HOME', str(conan_home))
27+
28+
1129
class TestConanProvider(ProviderIntegrationTestContract[ConanProvider]):
1230
"""The tests for the conan provider"""
1331

tests/unit/plugins/conan/test_install.py

Lines changed: 1 addition & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

tests/unit/plugins/conan/test_publish.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Unit tests for the conan plugin publish functionality"""
22

3-
from pathlib import Path
43
from typing import Any
54
from unittest.mock import MagicMock, Mock
65

@@ -286,50 +285,3 @@ def test_publish_list_pattern_creation(
286285

287286
# Verify ListPattern was created with correct reference pattern
288287
mock_list_pattern.assert_called_once_with(f'{ref.name}/*', package_id='*', only_recipe=False)
289-
290-
def test_publish_with_get_profile_returning_none_fallback(
291-
self,
292-
plugin: ConanProvider,
293-
conan_temp_conanfile: Path,
294-
conan_mock_api_publish: Mock,
295-
mocker: MockerFixture,
296-
) -> None:
297-
"""Test publish method when get_profile returns None (profile file corrupted/invalid)
298-
299-
Args:
300-
plugin: The plugin instance
301-
conan_temp_conanfile: Path to temporary conanfile.py
302-
conan_mock_api_publish: Mock ConanAPI instance configured for publish
303-
mocker: Pytest mocker fixture
304-
"""
305-
# Set plugin to local mode to avoid remote upload complications
306-
plugin.data = plugin.data.__class__(
307-
remotes=[],
308-
)
309-
310-
# Configure profiles to exist but get_profile returns None (corrupted/invalid profile)
311-
conan_mock_api_publish.profiles.get_default_host.return_value = '/path/to/host/profile'
312-
conan_mock_api_publish.profiles.get_default_build.return_value = '/path/to/build/profile'
313-
conan_mock_api_publish.profiles.get_profile.return_value = None # Profile file exists but is corrupted
314-
315-
# Mock ConanAPI constructor to return our configured mock
316-
mock_conan_api_constructor = mocker.patch(
317-
'cppython.plugins.conan.plugin.ConanAPI', return_value=conan_mock_api_publish
318-
)
319-
320-
# Execute - should not throw an exception despite get_profile returning None
321-
plugin.publish()
322-
323-
# Verify that despite get_profile returning None, the fallback was used
324-
mock_conan_api_constructor.assert_called_once()
325-
conan_mock_api_publish.profiles.get_default_host.assert_called_once()
326-
conan_mock_api_publish.profiles.get_default_build.assert_called_once()
327-
328-
# Should call get_profile twice (once for host, once for build)
329-
assert conan_mock_api_publish.profiles.get_profile.call_count == EXPECTED_PROFILE_CALLS
330-
331-
# Verify fallback profile creation was called (should be called twice for detect)
332-
assert conan_mock_api_publish.profiles.detect.call_count >= EXPECTED_PROFILE_CALLS
333-
334-
# Verify the rest of the process continued
335-
conan_mock_api_publish.export.export.assert_called_once()

0 commit comments

Comments
 (0)