Files
slic/tests/test_utils_get_adj.py
T
tligui_y e7f80fe52e
Run CI Tests / test (push) Successful in 51s
Update tests/test_utils_get_adj.py
2025-07-31 21:22:47 +02:00

58 lines
1.6 KiB
Python

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 *
@pytest.fixture(autouse=True)
def cleanup_adjustables():
yield
instances(Adjustable).clear()
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
@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("debug_internal", internal=True)
return a1, a2, a3
def test_get_adj_success(real_adjustables):
a1, _, _ = real_adjustables
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(real_adjustables):
a1, a2, a3 = real_adjustables
result = ensure_adjs(["contrast", a1, "debug_internal"])
assert result == (a2, a1, a3)
def test_get_adjs_filter(real_adjustables):
a1, a2, a3 = real_adjustables
public = get_adjs()
assert public == {"brightness": a1, "contrast": a2}
all_ = get_adjs(include_internal=True)
assert all_ == {"brightness": a1, "contrast": a2, "debug_internal": a3}