class WxButton(WxComponent): label = Attribute(constructor=WxLabelProperty) position = Attribute(constructor=WxPositionProperty) button = Attribute(constructor=WxButtonEventHandler) def create(self, index): return wx.Button(index.host.wx)
def test_set_position_on_getitem(self): attr = Attribute()[1] assert 1 == attr.position
def test_with_successfull_validation(self): assert {"my_attr": None} == \ _extract_values({"my_attr": Attribute(validator=lambda a: True)})
def test_raises_exception_when_validation_fails(self): with pytest.raises(AttributeValidationFailed): _extract_values({"my_attr": Attribute(validator=lambda a: False)})
def test_constructor(self): assert { "my_attr": 1 } == _extract_values({"my_attr": Attribute(constructor=int)}, my_attr="1")
def test_raises_exception_when_required_and_not_given(self): with pytest.raises(RequiredAttributeMissing): _extract_values({"my_attr": Attribute(required=True)})
def test_default_value_from_positional_attributes(self): assert {"my_attr": True} == \ _extract_values({"my_attr": Attribute(default=True, position=0)})
def test_default_is_none(self): assert {"my_attr": None} == _extract_values({"my_attr": Attribute()})
def test_from_sliced_positional_attribute(self): assert {"my_attr": [1, 3, 5]} == \ _extract_values({"my_attr": Attribute(position=slice(1, 6, 2))}, *tuple(range(9)))
def test_default_value_from_keyword_attributes(self): assert {"my_attr": True} == \ _extract_values({"my_attr": Attribute(default=True)})
def test_from_positional_attribute(self): assert {"my_attr": 1} == \ _extract_values({"my_attr": Attribute(position=0)}, 1)
def test_from_keyword_attributes(self): assert {"my_attr": 1} == \ _extract_values({"my_attr": Attribute()}, my_attr=1)
class WithAttributes(AttributeMixin): my_attr = Attribute()
def test_update_keep_attributes(self, create_component_class): component_class = create_component_class(my_attr=Attribute()) component = component_class(my_attr=True) component.update() assert component.my_attr
def test_update_attributes(self, create_component_class): component_class = create_component_class(my_attr=Attribute()) component = component_class(my_attr=True) component.update({"my_attr": False}) assert not component.my_attr