Beispiel #1
0
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)
Beispiel #2
0
 def test_set_position_on_getitem(self):
     attr = Attribute()[1]
     assert 1 == attr.position
Beispiel #3
0
 def test_with_successfull_validation(self):
     assert {"my_attr": None} == \
            _extract_values({"my_attr": Attribute(validator=lambda a: True)})
Beispiel #4
0
 def test_raises_exception_when_validation_fails(self):
     with pytest.raises(AttributeValidationFailed):
         _extract_values({"my_attr": Attribute(validator=lambda a: False)})
Beispiel #5
0
 def test_constructor(self):
     assert {
         "my_attr": 1
     } == _extract_values({"my_attr": Attribute(constructor=int)},
                          my_attr="1")
Beispiel #6
0
 def test_raises_exception_when_required_and_not_given(self):
     with pytest.raises(RequiredAttributeMissing):
         _extract_values({"my_attr": Attribute(required=True)})
Beispiel #7
0
 def test_default_value_from_positional_attributes(self):
     assert {"my_attr": True} == \
            _extract_values({"my_attr": Attribute(default=True, position=0)})
Beispiel #8
0
 def test_default_is_none(self):
     assert {"my_attr": None} == _extract_values({"my_attr": Attribute()})
Beispiel #9
0
 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)))
Beispiel #10
0
 def test_default_value_from_keyword_attributes(self):
     assert {"my_attr": True} == \
            _extract_values({"my_attr": Attribute(default=True)})
Beispiel #11
0
 def test_from_positional_attribute(self):
     assert {"my_attr": 1} == \
            _extract_values({"my_attr": Attribute(position=0)}, 1)
Beispiel #12
0
 def test_from_keyword_attributes(self):
     assert {"my_attr": 1} == \
            _extract_values({"my_attr": Attribute()}, my_attr=1)
Beispiel #13
0
 class WithAttributes(AttributeMixin):
     my_attr = Attribute()
Beispiel #14
0
 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
Beispiel #15
0
 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