This commit is contained in:
@@ -5,28 +5,6 @@ from slic.core.adjustable import Adjustable
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
from slic.utils.get_adj import *
|
||||
|
||||
def unregister_adj(target):
|
||||
weak_set = instances(Adjustable, weak=True)
|
||||
removed = 0
|
||||
|
||||
# Normaliser en liste
|
||||
targets = target if isinstance(target, (list, tuple, set)) else [target]
|
||||
|
||||
for item in targets:
|
||||
if isinstance(item, Adjustable):
|
||||
if item in weak_set:
|
||||
weak_set.discard(item)
|
||||
removed += 1
|
||||
elif isinstance(item, str):
|
||||
to_remove = [obj for obj in weak_set if obj.name == item]
|
||||
for obj in to_remove:
|
||||
weak_set.discard(obj)
|
||||
removed += len(to_remove)
|
||||
else:
|
||||
raise TypeError("target must be Adjustable, str, or iterable thereof")
|
||||
|
||||
return removed
|
||||
|
||||
|
||||
class SubAdjustable(Adjustable):
|
||||
def __init__(self, *a, **kw):
|
||||
@@ -43,18 +21,8 @@ class SubAdjustable(Adjustable):
|
||||
def is_moving(self):
|
||||
return False
|
||||
|
||||
@pytest.fixture
|
||||
def real_adjustables():
|
||||
a1 = SubAdjustable("brightness", units="%", limit_low=0, limit_high=100)
|
||||
a2 = SubAdjustable("contrast", units="%", limit_low=0, limit_high=100)
|
||||
a3 = SubAdjustable("mid_contrast", units="%", limit_low=0, limit_high=100)
|
||||
a4 = SubAdjustable("mid_brightness", units="%", limit_low=0, limit_high=100)
|
||||
a5 = SubAdjustable("debug_internal", internal=True)
|
||||
return a1, a2, a3, a4, a5
|
||||
|
||||
|
||||
def test_get_adj_success(real_adjustables):
|
||||
a1, _, _, _, _ = real_adjustables
|
||||
a1 = SubAdjustable("brightness", units="%", limit_low=0, limit_high=100)
|
||||
assert get_adj("brightness") is a1
|
||||
|
||||
def test_get_adj_not_found(capfd):
|
||||
@@ -62,12 +30,14 @@ def test_get_adj_not_found(capfd):
|
||||
get_adj("nonexistent")
|
||||
|
||||
def test_ensure_adjs_mixed(real_adjustables):
|
||||
_, a2, a3, _, _ = real_adjustables
|
||||
a2 = SubAdjustable("contrast", units="%", limit_low=0, limit_high=100)
|
||||
a3 = SubAdjustable("mid_contrast", units="%", limit_low=0, limit_high=100)
|
||||
result = ensure_adjs([a3, "contrast"])
|
||||
assert result == (a3, a2)
|
||||
|
||||
def test_get_adjs_filter(real_adjustables):
|
||||
_, _, _, a4, a5 = real_adjustables
|
||||
a4 = SubAdjustable("mid_brightness", units="%", limit_low=0, limit_high=100)
|
||||
a5 = SubAdjustable("debug_internal", internal=True)
|
||||
public = get_adjs()
|
||||
assert set(public) == {'brightness', 'contrast', 'mid_contrast', 'mid_brightness'}
|
||||
all_ = get_adjs(include_internal=True)
|
||||
|
||||
Reference in New Issue
Block a user