コード例 #1
0
  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)
コード例 #2
0
 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'}})
コード例 #3
0
 def testValidateShouldNotAttach(self):
   s = schema.from_spec({'required': ['a']})
   x = gcl.loads('a = 3')
   s.validate(x)
   self.assertEquals([], x.tuple_schema.required_fields)
コード例 #4
0
 def testTupleWithRequiredField(self):
   s = schema.from_spec({'required': ['a']})
   s.validate({'a': 3})
   with self.assertRaises(exceptions.SchemaError):
     s.validate({})
コード例 #5
0
ファイル: test_schema.py プロジェクト: mnuhn/gcl
 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'}})
コード例 #6
0
 def testTupleSchemaCorrectSubSchemaType(self):
   """To make sure we can't use tuple schemas incorrectly."""
   with self.assertRaises(ValueError):
     schema.from_spec({'fields': {'a': 'string'}}).validate({})
コード例 #7
0
 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})
コード例 #8
0
 def testTuple(self):
   schema.from_spec({}).validate({})
コード例 #9
0
 def testListWithSpecFails(self):
   string_schema = schema.ScalarSchema('string')
   with self.assertRaises(exceptions.SchemaError):
     schema.from_spec([string_schema]).validate([1, 2])
コード例 #10
0
 def testListSchema(self):
   with self.assertRaises(exceptions.SchemaError):
     schema.from_spec([]).validate('whoops')
コード例 #11
0
 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])
コード例 #12
0
 def testScalarBool(self):
   schema.from_spec('bool').validate(False)
コード例 #13
0
 def testScalarFloat(self):
   schema.from_spec('float').validate(3.0)
コード例 #14
0
 def testScalarIntFails(self):
   self.assertRaises(lambda: schema.from_spec('int').validate('a'))
コード例 #15
0
 def testScalarInt(self):
   schema.from_spec('int').validate(3)
コード例 #16
0
 def testScalarString(self):
   schema.from_spec('string').validate('a')