def testSchemasCompose3Times(self): x = gcl.loads(""" y = { x : int } { y : string } { z : bool }; """) self.assertEquals(schema.ScalarSchema('string'), x['y'].tuple_schema.get_subschema('y')) self.assertEquals(schema.ScalarSchema('int'), x['y'].tuple_schema.get_subschema('x')) self.assertEquals(schema.ScalarSchema('bool'), x['y'].tuple_schema.get_subschema('z'))
def testSchemasCompose(self): x = gcl.loads(""" Xint = { x : int; }; y = Xint { x = 'bla'; y : string }; """) self.assertEquals(schema.ScalarSchema('string'), x['y'].tuple_schema.get_subschema('y')) self.assertEquals(schema.ScalarSchema('int'), x['y'].tuple_schema.get_subschema('x'))
def testSchemaRefersToVariable(self): x = gcl.loads(""" Xint = { x : int; }; y : Xint = { x = 'bla' }; """) self.assertEquals(schema.ScalarSchema('int'), x['y'].tuple_schema.get_subschema('x'))
def testSubSchema(self): x = gcl.loads(""" a : int; """) self.assertEquals(schema.ScalarSchema('int'), x.tuple_schema.get_subschema('a'))
def setUp(self): self.int1 = schema.ScalarSchema('int') self.int2 = schema.ScalarSchema('int') self.string = schema.ScalarSchema('string')
def testListWithSpecFails(self): string_schema = schema.ScalarSchema('string') with self.assertRaises(exceptions.SchemaError): schema.from_spec([string_schema]).validate([1, 2])
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 testInheritSchemaWithOverriddenValueWhichIsAList(self): x = gcl.loads(""" y = { x : [int] } { x = [3] }; """) self.assertEquals(schema.ListSchema(schema.ScalarSchema('int')), x['y'].tuple_schema.get_subschema('x'))
def testListSchema(self): x = gcl.loads(""" y = { x : [int] } """) self.assertEquals(schema.ListSchema(schema.ScalarSchema('int')), x['y'].tuple_schema.get_subschema('x'))
def testInheritSchemaWithOverriddenValue(self): x = gcl.loads(""" y = { x : int } { x = 3 }; """) self.assertEquals(schema.ScalarSchema('int'), x['y'].tuple_schema.get_subschema('x'))
def testCollapseEqualSchemas(self): self.collapsesTo(schema.ScalarSchema('int'), schema.ScalarSchema('int'), schema.ScalarSchema('int'))
def testCollapseAniesRight(self): self.collapsesTo(schema.ScalarSchema('int'), schema.AnySchema(), schema.ScalarSchema('int'))