This commit is contained in:
@@ -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)
|
||||
# 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)
|
||||
Reference in New Issue
Block a user