TUIX v0.1Alpha
Testing
Guidelines for testing TUIX Core components and configurations.
Testing Component Creation
Test that components are created correctly with expected default values. Verify that duplicate IDs and unknown types raise 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')Testing Properties
Verify that set_property() correctly assigns values and that type/property mismatches raise errors.
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=[])Testing Styles
Test that custom style overrides are applied correctly and that the style cascade works as expected.
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)Testing Layout
Verify dimension constraints and margin mode restrictions.
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)Testing Utilities
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