From 43ba4799374616026d8e7ea722ac591bc632fc40 Mon Sep 17 00:00:00 2001 From: tligui_y Date: Wed, 30 Jul 2025 02:52:51 +0200 Subject: [PATCH] Update tests/test_utils_snapshot.py --- tests/test_utils_snapshot.py | 48 +++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/tests/test_utils_snapshot.py b/tests/test_utils_snapshot.py index 82fb6b792..bb5c8a230 100644 --- a/tests/test_utils_snapshot.py +++ b/tests/test_utils_snapshot.py @@ -4,7 +4,7 @@ from slic.utils.snapshot import snapshot from slic.core.adjustable import Adjustable class FakeAdjustable(Adjustable): - """Mock isolé sans dépendance à _instances""" + """Mock complètement isolé""" def __init__(self, ID, name=None, internal=False): super().__init__(ID=ID, name=name or ID, internal=internal) self._value = 0 @@ -23,50 +23,58 @@ class FakeAdjustable(Adjustable): # Configuration des tests test_cases = [ + # Test 1: Exclusion des internes pytest.param( [("v1", "Visible", False), ("h1", "Hidden", True)], ["Visible"], {}, id="exclude_internals" ), + # Test 2: Inclusion des internes pytest.param( [("v1", "Visible", False), ("h1", "Hidden", True)], ["Visible", "Hidden"], {"include_internal": True}, id="include_internals" ), + # Test 3: Cas vide pytest.param( [], [], {}, id="empty_case" ), + # Test 4: Tri alphabétique pytest.param( [("3", "C"), ("1", "A"), ("2", "B")], ["A", "B", "C"], {"sort_key": str}, - id="sort_by_str" + id="sort_alphabetical" ) ] +@pytest.fixture +def mock_registry(): + """Fixture pour isoler complètement la registry""" + with patch('slic.utils.registry.instances') as mock: + yield mock + @pytest.mark.parametrize("test_input,expected,kwargs", test_cases) -def test_snapshot(test_input, expected, kwargs): - """Version finale avec isolation garantie""" - # 1. Création des objets de test +def test_snapshot(test_input, expected, kwargs, mock_registry): + """Version finale avec isolation absolue""" + # 1. Création des objets de test FRAIS test_objects = [FakeAdjustable(*args) for args in test_input] - # 2. Mocking complet - with patch('slic.utils.registry.instances') as mock_instances: - # Configuration du mock - mock_instances.return_value = test_objects - - # 3. Exécution - result = snapshot(**kwargs) - - # 4. Vérification - if not expected: - assert result == [] - elif 'sort_key' in kwargs: - assert [x.name for x in result] == expected - else: - assert {x.name for x in result} == set(expected) \ No newline at end of file + # 2. Configuration du mock + mock_registry.return_value = test_objects + + # 3. Exécution + result = snapshot(**kwargs) + + # 4. Vérification + if not expected: + assert result == [] + elif 'sort_key' in kwargs: + assert [x.name for x in result] == expected + else: + assert {x.name for x in result} == set(expected) \ No newline at end of file