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 """)
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
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 """)
def test_attr(self): el = Element("foo") el.text = "bar" assert validate(attr({"text": text}), el).text == "bar"
def test_attr(self): el = Element("foo") el.text = "bar" assert validate(attr({"text": text}), el).text == "bar"