Files
slic/tests/test_utils_snapshot.py
T
tligui_y ef363efe8b
Run CI Tests / test (push) Successful in 37s
Update tests/test_utils_snapshot.py
2025-07-30 02:24:12 +02:00

84 lines
2.4 KiB
Python

import pytest
from unittest.mock import patch, MagicMock
from slic.utils.snapshot import snapshot
from slic.core.adjustable import Adjustable
class FakeAdjustable(Adjustable):
"""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
def get_current_value(self):
return self._value
def is_moving(self):
return False
def set_target_value(self, value, *args, **kwargs):
return value
def __str__(self):
return self.name
# Tous les cas de test
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
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)