def testTupleSchemaSubSchema(self): s = schema.from_spec({'fields': {'a': schema.from_spec('string')}}) # Subschema for a requires a string with self.assertRaises(exceptions.SchemaError): s.get_subschema('a').validate(3) # No schema, so don't care s.get_subschema('b').validate(3)
def testTupleWithDeepSchemas(self): s = schema.from_spec({ 'fields': { 'a': schema.from_spec({'fields': { 'b': schema.from_spec('int') }}) } }) s.validate({'a': {}}) # This doesn't fail! No deep verification! s.validate({'a': {'b': 'c'}})
def testValidateShouldNotAttach(self): s = schema.from_spec({'required': ['a']}) x = gcl.loads('a = 3') s.validate(x) self.assertEquals([], x.tuple_schema.required_fields)
def testTupleWithRequiredField(self): s = schema.from_spec({'required': ['a']}) s.validate({'a': 3}) with self.assertRaises(exceptions.SchemaError): s.validate({})
def testTupleWithDeepSchemas(self): s = schema.from_spec({'fields': {'a': schema.from_spec({'fields': { 'b': schema.from_spec('int') }})}}) s.validate({'a': {}}) # This doesn't fail! No deep verification! s.validate({'a': {'b': 'c'}})
def testTupleSchemaCorrectSubSchemaType(self): """To make sure we can't use tuple schemas incorrectly.""" with self.assertRaises(ValueError): schema.from_spec({'fields': {'a': 'string'}}).validate({})
def testTupleWithSubSchemas(self): s = schema.from_spec({'fields': {'a': schema.from_spec('string')}}) s.validate({'a': 'b'}) s.validate({}) # This doesn't fail! TupleSchema only checks required fields! s.validate({'a': 3})
def testTuple(self): schema.from_spec({}).validate({})
def testListWithSpecFails(self): string_schema = schema.ScalarSchema('string') with self.assertRaises(exceptions.SchemaError): schema.from_spec([string_schema]).validate([1, 2])
def testListSchema(self): with self.assertRaises(exceptions.SchemaError): schema.from_spec([]).validate('whoops')
def testListWithSpec(self): int_schema = schema.ScalarSchema('int') schema.from_spec([int_schema]).validate([3]) schema.from_spec([int_schema]).validate([]) schema.from_spec([int_schema]).validate([1, 2]) schema.from_spec([]).validate([1, 2])
def testScalarBool(self): schema.from_spec('bool').validate(False)
def testScalarFloat(self): schema.from_spec('float').validate(3.0)
def testScalarIntFails(self): self.assertRaises(lambda: schema.from_spec('int').validate('a'))
def testScalarInt(self): schema.from_spec('int').validate(3)
def testScalarString(self): schema.from_spec('string').validate('a')