def test_raises_exception_when_validation_fails(self): with pytest.raises(AttributeValidationFailed): _extract_values({"my_attr": Attribute(validator=lambda a: False)})
def test_raises_exception_when_required_and_not_given(self): with pytest.raises(RequiredAttributeMissing): _extract_values({"my_attr": Attribute(required=True)})
def test_with_successfull_validation(self): assert {"my_attr": None} == \ _extract_values({"my_attr": Attribute(validator=lambda a: True)})
def test_default_is_none(self): assert {"my_attr": None} == _extract_values({"my_attr": Attribute()})
def test_constructor(self): assert { "my_attr": 1 } == _extract_values({"my_attr": Attribute(constructor=int)}, my_attr="1")
def test_default_value_from_positional_attributes(self): assert {"my_attr": True} == \ _extract_values({"my_attr": Attribute(default=True, position=0)})
def test_default_value_from_keyword_attributes(self): assert {"my_attr": True} == \ _extract_values({"my_attr": Attribute(default=True)})
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_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)