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