Example #1
0
 def test_failure_missing(self, obj):
     with pytest.raises(validate.ValidationError) as cm:
         validate.validate(validate.attr({"missing": int}), obj)
     assert_validationerror(
         cm.value, """
         ValidationError(AttrSchema):
           Attribute 'missing' not found on object Subject
     """)
Example #2
0
 def test_success(self, obj):
     schema = validate.attr(
         {"foo": validate.transform(lambda num: num + 1)})
     newobj = validate.validate(schema, obj)
     assert obj.foo == 1
     assert newobj is not obj
     assert newobj.foo == 2
     assert newobj.bar is obj.bar
Example #3
0
 def test_failure_subschema(self, obj):
     with pytest.raises(validate.ValidationError) as cm:
         validate.validate(validate.attr({"foo": str}), obj)
     assert_validationerror(
         cm.value, """
         ValidationError(AttrSchema):
           Could not validate attribute 'foo'
           Context(type):
             Type of 1 should be str, but is int
     """)
Example #4
0
    def test_attr(self):
        el = Element("foo")
        el.text = "bar"

        assert validate(attr({"text": text}), el).text == "bar"
Example #5
0
    def test_attr(self):
        el = Element("foo")
        el.text = "bar"

        assert validate(attr({"text": text}), el).text == "bar"