This commit is contained in:
@@ -18,65 +18,80 @@ class FakeAdjustable(Adjustable):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def make_test_id(val):
|
||||
"""Generate readable test IDs"""
|
||||
def test_id(val):
|
||||
"""Generate stable test IDs for all cases"""
|
||||
# val is the entire parameter tuple (test_input, expected, kwargs)
|
||||
if not val[1]: # Empty expected list
|
||||
return "empty"
|
||||
if isinstance(val[1][0], str):
|
||||
if val[2].get('include_internal'):
|
||||
return "include_internals"
|
||||
if 'sort_key' in val[2]:
|
||||
return f"sort_{val[2]['sort_key'].__name__}"
|
||||
return val[1][0].lower()
|
||||
return str(val[1][0])
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected,kwargs", [
|
||||
test_cases = [
|
||||
# Basic functionality
|
||||
(
|
||||
pytest.param(
|
||||
[("v1", "Visible", False), ("h1", "Hidden", True)],
|
||||
["Visible"],
|
||||
{}
|
||||
{},
|
||||
id="exclude_internals"
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
[("v1", "Visible", False), ("h1", "Hidden", True)],
|
||||
["Visible", "Hidden"],
|
||||
{"include_internal": True}
|
||||
{"include_internal": True},
|
||||
id="include_internals"
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
[],
|
||||
[],
|
||||
{}
|
||||
{},
|
||||
id="empty_case"
|
||||
),
|
||||
|
||||
# All sorting variants
|
||||
(
|
||||
# Sorting variants
|
||||
pytest.param(
|
||||
[("3", "C"), ("1", "A"), ("2", "B")],
|
||||
["A", "B", "C"],
|
||||
{"sort_key": repr}
|
||||
{"sort_key": repr},
|
||||
id="sort_repr"
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
[("3", "C"), ("1", "A"), ("2", "B")],
|
||||
["A", "B", "C"],
|
||||
{"sort_key": str}
|
||||
{"sort_key": str},
|
||||
id="sort_str"
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
[("3", "C"), ("1", "A"), ("2", "B")],
|
||||
["A", "B", "C"],
|
||||
{"sort_key": lambda a: a.ID}
|
||||
{"sort_key": lambda a: a.ID},
|
||||
id="sort_by_id"
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
[("3", "Charlie"), ("1", "alpha"), ("2", "Beta")],
|
||||
["alpha", "Beta", "Charlie"],
|
||||
{"sort_key": lambda a: a.name.lower()}
|
||||
{"sort_key": lambda a: a.name.lower()},
|
||||
id="sort_case_insensitive"
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
[("1", "A"), ("2", "BB"), ("3", "CCC")],
|
||||
["A", "BB", "CCC"],
|
||||
{"sort_key": lambda a: len(a.name)}
|
||||
{"sort_key": lambda a: len(a.name)},
|
||||
id="sort_by_length"
|
||||
)
|
||||
], ids=make_test_id)
|
||||
]
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected,kwargs", test_cases)
|
||||
def test_snapshot(test_input, expected, kwargs):
|
||||
"""Complete test with proper instance mocking"""
|
||||
# Create test objects
|
||||
test_objects = [FakeAdjustable(*args) for args in test_input]
|
||||
|
||||
# Mock the registry system at two levels:
|
||||
# Mock the registry system
|
||||
with patch('slic.utils.registry.instances') as mock_instances, \
|
||||
patch('slic.core.adjustable.Adjustable._instances', new_callable=MagicMock) as mock_adj:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user