TUIX v0.1Alfa
Testování
Doporučení pro testování komponent a konfigurací TUIX Core.
Testování vytvoření komponent
Otestujte, že se komponenty vytvářejí správně s očekávanými výchozími hodnotami. Ověřte, že duplicitní ID a neznámé typy vyvolají ValueError.
import pytest
from tuix.core import TuixEngine
def test_create_choice():
engine = TuixEngine()
engine.components.create('choice', 'test_menu')
obj = engine.components.get('test_menu')
assert obj['type'] == 'choice'
assert obj['label'] == ''
assert obj['choices'] == []
def test_duplicate_id_raises():
engine = TuixEngine()
engine.components.create('choice', 'dup')
with pytest.raises(ValueError):
engine.components.create('choice', 'dup')
def test_unknown_type_raises():
engine = TuixEngine()
with pytest.raises(ValueError):
engine.components.create('unknown_type', 'test')Testování vlastností
Ověřte, že set_property() správně přiřazuje hodnoty a že neshody typu/vlastnosti vyvolají chyby.
def test_set_label():
engine = TuixEngine()
engine.components.create('choice', 'menu')
engine.components.set_property(id='menu', param='label', value='Hello')
assert engine.components.get('menu')['label'] == 'Hello'
def test_wrong_property_raises():
engine = TuixEngine()
engine.components.create('progress_bar', 'bar')
with pytest.raises(ValueError):
engine.components.set_property(id='bar', param='choices', value=[])Testování stylů
Otestujte, že se vlastní přepisy stylů aplikují správně a že kaskáda stylů funguje podle očekávání.
def test_custom_style_override():
engine = TuixEngine()
engine.styles.set_custom_style(key='border', value=(255, 0, 0))
assert engine.styles.cached_styles['border'] == (255, 0, 0)
def test_remove_custom_falls_back():
engine = TuixEngine()
engine.styles.set_custom_style(key='border', value=(255, 0, 0))
engine.styles.remove_custom_style('border')
# Falls back to classic preset
assert engine.styles.cached_styles['border'] == (255, 255, 255)Testování layoutu
Ověřte omezení rozměrů a režimů okrajů.
def test_dimension_bounds():
engine = TuixEngine()
engine.components.create('choice', 'test')
with pytest.raises(ValueError):
engine.layout.set_dimensions(id='test', width_modifier=1.5)
def test_centered_margin_restriction():
engine = TuixEngine()
engine.components.create('choice', 'test')
engine.layout.margin_mode(id='test', param='margin_top', mode='centered')
with pytest.raises(ValueError):
engine.layout.set_dimensions(id='test', margin_top=0.1)Testování utility funkcí
from tuix.core import is_rgb, blend_shadow, text_color, visual_width
def test_is_rgb():
assert is_rgb((255, 0, 0)) is True
assert is_rgb((256, 0, 0)) is False
assert is_rgb('red') is False
assert is_rgb((0, 0)) is False
def test_blend_shadow():
result = blend_shadow((0, 0, 0), (100, 100, 100), 0.5)
assert result == (50, 50, 50)
def test_text_color():
assert text_color(255, 0, 0) == '\033[38;2;255;0;0m'
def test_visual_width():
assert visual_width('abc') == 3