Esempio n. 1
0
    def test_serialize_schema(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()
        x1 = m.new('X', Boolean=True, Integer=4, String='str')
        x2 = m.new('X', Boolean=True, Integer=4, String='str')
        xtuml.relate(x1, x2, 1, 'precedes')
        
        s = xtuml.serialize_schema(m)
        loader = xtuml.ModelLoader()
        loader.input(s)
        m = loader.build_metamodel()

        self.assertFalse(m.select_any('X'))

        x1 = m.new('X', Boolean=True, Integer=4, String='str')
        x2 = m.new('X', Boolean=True, Integer=4, String='str')
        xtuml.relate(x1, x2, 1, 'succeeds')

        self.assertTrue(xtuml.navigate_one(x1).X[1, 'succeeds']())
Esempio n. 2
0
    def test_serialize_schema(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()
        x1 = m.new('X', Boolean=True, Integer=4, String='str')
        x2 = m.new('X', Boolean=True, Integer=4, String='str')
        xtuml.relate(x1, x2, 1, 'precedes')

        s = xtuml.serialize_schema(m)
        loader = xtuml.ModelLoader()
        loader.input(s)
        m = loader.build_metamodel()

        self.assertFalse(m.select_any('X'))

        x1 = m.new('X', Boolean=True, Integer=4, String='str')
        x2 = m.new('X', Boolean=True, Integer=4, String='str')
        xtuml.relate(x1, x2, 1, 'succeeds')

        self.assertTrue(xtuml.navigate_one(x1).X[1, 'succeeds']())
Esempio n. 3
0
    def compare_wrapper(self, *args, **kwargs):
        loader = xtuml.ModelLoader()
        loader.input(fn.__doc__)
        m1 = loader.build_metamodel()
        
        s = xtuml.serialize_schema(m1)

        loader = xtuml.ModelLoader()
        loader.input(s)
        m2 = loader.build_metamodel()
        
        self.assertTrue(compare_metamodel_classes(m1, m2))
        fn(self)
Esempio n. 4
0
    def compare_wrapper(self, *args, **kwargs):
        loader = xtuml.ModelLoader()
        loader.input(fn.__doc__)
        m1 = loader.build_metamodel()

        s = xtuml.serialize_schema(m1)

        loader = xtuml.ModelLoader()
        loader.input(s)
        m2 = loader.build_metamodel()

        self.assertTrue(compare_metamodel_classes(m1, m2))
        fn(self)
Esempio n. 5
0
    def test_serialize_unique_identifiers(self):
        schema = '''
        CREATE TABLE X (s1 STRING, s2 STRING);
        CREATE UNIQUE INDEX I1 ON X (s1, s2);
        '''
        
        loader = xtuml.ModelLoader()
        loader.input(schema)
        m = loader.build_metamodel()
        
        s = xtuml.serialize_schema(m)
        s += xtuml.serialize_unique_identifiers(m)
        
        loader = xtuml.ModelLoader()
        loader.input(s)
        m = loader.build_metamodel()

        x1 = m.new('X', s1='s1', s2='s2')
        x2 = m.new('X', s1='s1', s2='s2')

        self.assertFalse(m.is_consistent())
        x2.s2 = 'S2'
        self.assertTrue(m.is_consistent())
Esempio n. 6
0
    def test_serialize_unique_identifiers(self):
        schema = '''
        CREATE TABLE X (s1 STRING, s2 STRING);
        CREATE UNIQUE INDEX I1 ON X (s1, s2);
        '''

        loader = xtuml.ModelLoader()
        loader.input(schema)
        m = loader.build_metamodel()

        s = xtuml.serialize_schema(m)
        s += xtuml.serialize_unique_identifiers(m)

        loader = xtuml.ModelLoader()
        loader.input(s)
        m = loader.build_metamodel()

        x1 = m.new('X', s1='s1', s2='s2')
        x2 = m.new('X', s1='s1', s2='s2')

        self.assertFalse(m.is_consistent())
        x2.s2 = 'S2'
        self.assertTrue(m.is_consistent())
Esempio n. 7
0
 def test_persist_schema(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 ( UNIQUE_ID ) PHRASE 'precedes'
                          TO   1C X ( Next ) PHRASE 'succeeds';
     '''
     loader = xtuml.ModelLoader()
     loader.input(schema)
     m = loader.build_metamodel()
     s = xtuml.serialize_schema(m)
 
     (_, filename) = tempfile.mkstemp()
     try:
         xtuml.persist_schema(m, filename)
         with open(filename) as f:
             self.assertEqual(s, f.read())
     finally:
         atexit.register(os.remove, filename)
Esempio n. 8
0
    def test_persist_schema(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 ( UNIQUE_ID ) PHRASE 'precedes'
                             TO   1C X ( Next ) PHRASE 'succeeds';
        '''
        loader = xtuml.ModelLoader()
        loader.input(schema)
        m = loader.build_metamodel()
        s = xtuml.serialize_schema(m)

        (_, filename) = tempfile.mkstemp()
        try:
            xtuml.persist_schema(m, filename)
            with open(filename) as f:
                self.assertEqual(s, f.read())
        finally:
            atexit.register(os.remove, filename)