Пример #1
0
 def testSchemaGeneration(self):
     tableSpecs = NamedKeyDict({})
     for element in self.universe.getStaticElements():
         if element.hasTable and element.viewOf is None:
             tableSpecs[element] = element.RecordClass.fields.makeTableSpec(
                 RegionReprClass=SpatialRegionDatabaseRepresentation,
                 TimespanReprClass=TimespanDatabaseRepresentation.Compound
             )
     for element, tableSpec in tableSpecs.items():
         for dep in element.required:
             with self.subTest(element=element.name, dep=dep.name):
                 if dep != element:
                     self.assertIn(dep.name, tableSpec.fields)
                     self.assertEqual(tableSpec.fields[dep.name].dtype, dep.primaryKey.dtype)
                     self.assertEqual(tableSpec.fields[dep.name].length, dep.primaryKey.length)
                     self.assertEqual(tableSpec.fields[dep.name].nbytes, dep.primaryKey.nbytes)
                     self.assertFalse(tableSpec.fields[dep.name].nullable)
                     self.assertTrue(tableSpec.fields[dep.name].primaryKey)
                 else:
                     self.assertIn(element.primaryKey.name, tableSpec.fields)
                     self.assertEqual(tableSpec.fields[element.primaryKey.name].dtype,
                                      dep.primaryKey.dtype)
                     self.assertEqual(tableSpec.fields[element.primaryKey.name].length,
                                      dep.primaryKey.length)
                     self.assertEqual(tableSpec.fields[element.primaryKey.name].nbytes,
                                      dep.primaryKey.nbytes)
                     self.assertFalse(tableSpec.fields[element.primaryKey.name].nullable)
                     self.assertTrue(tableSpec.fields[element.primaryKey.name].primaryKey)
         for dep in element.implied:
             with self.subTest(element=element.name, dep=dep.name):
                 self.assertIn(dep.name, tableSpec.fields)
                 self.assertEqual(tableSpec.fields[dep.name].dtype, dep.primaryKey.dtype)
                 self.assertFalse(tableSpec.fields[dep.name].primaryKey)
         for foreignKey in tableSpec.foreignKeys:
             self.assertIn(foreignKey.table, tableSpecs)
             self.assertIn(foreignKey.table, element.graph.dimensions.names)
             self.assertEqual(len(foreignKey.source), len(foreignKey.target))
             for source, target in zip(foreignKey.source, foreignKey.target):
                 self.assertIn(source, tableSpec.fields.names)
                 self.assertIn(target, tableSpecs[foreignKey.table].fields.names)
                 self.assertEqual(tableSpec.fields[source].dtype,
                                  tableSpecs[foreignKey.table].fields[target].dtype)
                 self.assertEqual(tableSpec.fields[source].length,
                                  tableSpecs[foreignKey.table].fields[target].length)
                 self.assertEqual(tableSpec.fields[source].nbytes,
                                  tableSpecs[foreignKey.table].fields[target].nbytes)
Пример #2
0
 def testSchemaGeneration(self):
     tableSpecs = NamedKeyDict({})
     for element in self.universe.elements:
         if element.hasTable and element.viewOf is None:
             tableSpecs[element] = makeDimensionElementTableSpec(element)
     for element, tableSpec in tableSpecs.items():
         for dep in element.required:
             with self.subTest(element=element.name, dep=dep.name):
                 if dep != element:
                     self.assertIn(dep.name, tableSpec.fields)
                     self.assertEqual(tableSpec.fields[dep.name].dtype,
                                      dep.primaryKey.dtype)
                     self.assertEqual(tableSpec.fields[dep.name].length,
                                      dep.primaryKey.length)
                     self.assertEqual(tableSpec.fields[dep.name].nbytes,
                                      dep.primaryKey.nbytes)
                     self.assertFalse(tableSpec.fields[dep.name].nullable)
                     self.assertTrue(tableSpec.fields[dep.name].primaryKey)
                 else:
                     self.assertIn(element.primaryKey.name,
                                   tableSpec.fields)
                     self.assertEqual(
                         tableSpec.fields[element.primaryKey.name].dtype,
                         dep.primaryKey.dtype)
                     self.assertEqual(
                         tableSpec.fields[element.primaryKey.name].length,
                         dep.primaryKey.length)
                     self.assertEqual(
                         tableSpec.fields[element.primaryKey.name].nbytes,
                         dep.primaryKey.nbytes)
                     self.assertFalse(
                         tableSpec.fields[element.primaryKey.name].nullable)
                     self.assertTrue(tableSpec.fields[
                         element.primaryKey.name].primaryKey)
         for dep in element.implied:
             with self.subTest(element=element.name, dep=dep.name):
                 self.assertIn(dep.name, tableSpec.fields)
                 self.assertEqual(tableSpec.fields[dep.name].dtype,
                                  dep.primaryKey.dtype)
                 self.assertFalse(tableSpec.fields[dep.name].primaryKey)
         for foreignKey in tableSpec.foreignKeys:
             self.assertIn(foreignKey.table, tableSpecs)
             self.assertIn(foreignKey.table, element.graph.dimensions.names)
             self.assertEqual(len(foreignKey.source),
                              len(foreignKey.target))
             for source, target in zip(foreignKey.source,
                                       foreignKey.target):
                 self.assertIn(source, tableSpec.fields.names)
                 self.assertIn(target,
                               tableSpecs[foreignKey.table].fields.names)
                 self.assertEqual(
                     tableSpec.fields[source].dtype,
                     tableSpecs[foreignKey.table].fields[target].dtype)
                 self.assertEqual(
                     tableSpec.fields[source].length,
                     tableSpecs[foreignKey.table].fields[target].length)
                 self.assertEqual(
                     tableSpec.fields[source].nbytes,
                     tableSpecs[foreignKey.table].fields[target].nbytes)
         self.assertEqual(tuple(tableSpec.fields.names),
                          element.RecordClass.__slots__)