def testPersistDatabase(self): schema = ''' CREATE TABLE X (BOOLEAN BOOLEAN, INTEGER INTEGER, REAL REAL, STRING STRING, UNIQUE_ID UNIQUE_ID, Next UNIQUE_ID); CREATE ROP REF_ID R1 FROM 1C X ( Next ) PHRASE 'precedes' TO 1C X ( UNIQUE_ID ) PHRASE 'succeeds'; ''' loader = xtuml.ModelLoader() loader.input(schema) m = loader.build_metamodel() m.new('X', Boolean=True, Integer=4, String='str', Uniquie_Id=5) s = xtuml.serialize_database(m) (_, filename) = tempfile.mkstemp() try: xtuml.persist_database(m, filename) with open(filename) as f: self.assertEqual(s, f.read()) finally: os.remove(filename)
def testSerializeUndefinedTable(self): schema = ''' CREATE TABLE X ( _0 UNIQUE_ID, _1 STRING, _2 STRING, _3 INTEGER, _4 INTEGER, _5 BOOLEAN, _6 BOOLEAN, _7 INTEGER, _8 REAL, _9 REAL ); ''' instances = ''' INSERT INTO X VALUES ( "00000000-0000-0000-0000-000000000000", 'TE''ST', 'test', 1, 0, false, true, -5, 1.543, -0.543 ); ''' loader = xtuml.ModelLoader() loader.input(instances) m = loader.build_metamodel() s1 = xtuml.serialize_database(m) loader = xtuml.ModelLoader() loader.input(schema) loader.input(instances) m = loader.build_metamodel() s2 = xtuml.serialize_database(m) self.assertEqual(s1, s2)
def test_serialize_undefined_table(self): schema = ''' CREATE TABLE X ( _0 UNIQUE_ID, _1 STRING, _2 STRING, _3 INTEGER, _4 INTEGER, _5 BOOLEAN, _6 BOOLEAN, _7 INTEGER, _8 REAL, _9 REAL ); ''' instances = ''' INSERT INTO X VALUES ( "00000000-0000-0000-0000-000000000000", 'TE''ST', 'test', 1, 0, false, true, -5, 1.543, -0.543 ); ''' loader = xtuml.ModelLoader() loader.input(instances) m = loader.build_metamodel() s1 = xtuml.serialize_database(m) loader = xtuml.ModelLoader() loader.input(schema) loader.input(instances) m = loader.build_metamodel() s2 = xtuml.serialize_database(m) self.assertEqual(s1, s2)
def test_implicit_serialize(self): schema = ''' CREATE TABLE X (BOOLEAN BOOLEAN, INTEGER INTEGER, REAL REAL, STRING STRING, UNIQUE_ID UNIQUE_ID, Next UNIQUE_ID); CREATE ROP REF_ID R1 FROM 1C X ( Next ) PHRASE 'precedes' TO 1C X ( UNIQUE_ID ) PHRASE 'succeeds'; ''' loader = xtuml.ModelLoader() loader.input(schema) m = loader.build_metamodel() X = m.find_class('X') s1 = xtuml.serialize(X) s2 = xtuml.serialize_class(X) self.assertTrue(s1) self.assertEqual(s1, s2) R1 = m.associations[0] s1 = xtuml.serialize(R1) s2 = xtuml.serialize_association(R1) self.assertTrue(s1) self.assertEqual(s1, s2) x = m.new('X', Boolean=True, Integer=4, String='str') s1 = xtuml.serialize(x) s2 = xtuml.serialize_instance(x) self.assertTrue(s1) self.assertEqual(s1, s2) s1 = xtuml.serialize(m) s2 = xtuml.serialize_database(m) self.assertTrue(s1) self.assertEqual(s1, s2)