Update tests/test_utils_snapshot.py
Run CI Tests / test (push) Successful in 32s

This commit is contained in:
2025-07-30 02:36:20 +02:00
parent ef363efe8b
commit 406c7bccdb
+19 -31
View File
@@ -4,7 +4,7 @@ from slic.utils.snapshot import snapshot
from slic.core.adjustable import Adjustable
class FakeAdjustable(Adjustable):
"""Mock complètement isolé"""
"""Mock isolé sans dépendance à _instances"""
def __init__(self, ID, name=None, internal=False):
super().__init__(ID=ID, name=name or ID, internal=internal)
self._value = 0
@@ -21,64 +21,52 @@ class FakeAdjustable(Adjustable):
def __str__(self):
return self.name
# Tous les cas de test
# Configuration des tests
test_cases = [
# Exclusion des internes
pytest.param(
[("v1", "Visible", False), ("h1", "Hidden", True)],
["Visible"],
{},
id="exclude_internals"
),
# Inclusion des internes
pytest.param(
[("v1", "Visible", False), ("h1", "Hidden", True)],
["Visible", "Hidden"],
{"include_internal": True},
id="include_internals"
),
# Cas vide
pytest.param(
[],
[],
{},
id="empty_case"
),
# Tri par string
pytest.param(
[("3", "C"), ("1", "A"), ("2", "B")],
["A", "B", "C"],
{"sort_key": str},
id="sort_by_str"
),
# Tri par ID
pytest.param(
[("3", "Z"), ("1", "A"), ("2", "M")],
["A", "M", "Z"],
{"sort_key": lambda a: a.ID},
id="sort_by_id"
)
]
@pytest.mark.parametrize("test_input,expected,kwargs", test_cases)
def test_snapshot(test_input, expected, kwargs):
"""Tests avec isolation absolue"""
# Création des objets frais pour CE TEST uniquement
"""Version finale avec isolation garantie"""
# 1. Création des objets de test
test_objects = [FakeAdjustable(*args) for args in test_input]
# Mock COMPLET de la registry
mock_registry = MagicMock()
mock_registry.return_value = test_objects
with patch('slic.utils.registry.instances', new=mock_registry):
# Mock aussi le registry interne si nécessaire
with patch('slic.core.adjustable.Adjustable._instances', new=test_objects):
result = snapshot(**kwargs)
# 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)
# 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)