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