def test_inner_schema(self): s = ObjectSchema( b=schema.And(int, lambda x: x > 98, lambda x: x < 100)) output = s.validate(self.data) # validation preserves identity self.assertIs(output, self.data) # this schema does not change objects: self.assertEqual(output.a, "hello") self.assertEqual(output.b, 99)
def test_inner_schema(self): s = ObjectSchema( b=schema.And(int, lambda x: x > 98, lambda x: x < 100) ) output = s.validate(self.data) # validation preserves identity self.assertIs(output, self.data) # this schema does not change objects: self.assertEqual(output.a, "hello") self.assertEqual(output.b, 99)
def test_simple(self): s = ObjectSchema(a="hello", b=int) output = s.validate(self.data) # validation preserves identity self.assertIs(output, self.data) # this schema does not change objects: self.assertEqual(output.a, "hello") self.assertEqual(output.b, 99) # It tolerates additional fields self.data.c = "another field" output = s.validate(self.data) self.assertIs(output, self.data) # It detects field schema mismatches self.data.a = "not hello" with self.assertRaises(schema.SchemaError): s.validate(self.data) # And it detects missing fields del self.data.a with self.assertRaises(schema.SchemaError): s.validate(self.data)