import pytest import sys import os 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 * class SubAdjustable(Adjustable): def __init__(self, *a, **kw): super().__init__(*a, **kw) self._val = 0 def get_current_value(self): return self._val def set_target_value(self, v, *args, **kwargs): self._val = v return v def is_moving(self): return False def test_get_adj_success(): a1 = SubAdjustable("brightness", units="%", limit_low=0, limit_high=100) assert get_adj("brightness") is a1 def test_get_adj_not_found(capfd): with pytest.raises(ValueError, match='could not find Adjustable with name "nonexistent"') as exc_info: get_adj("nonexistent") def test_ensure_adjs_mixed(): 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(): 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) assert set(all_) == {'brightness', 'contrast', 'mid_contrast', 'mid_brightness', 'debug_internal'}