Beispiel #1
0
 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)
Beispiel #2
0
 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)
Beispiel #3
0
    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)
Beispiel #4
0
    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)
Beispiel #5
0
 def test_repr(self):
     s = ObjectSchema(a="hello", b=int)
     self.assertEqual(repr(s), "ObjectSchema(a='hello', b=%s)" % int)