Ejemplo n.º 1
0
 def test_remove_globals(self):
     m = ooaofooa.empty_model(load_globals=False)
     s = xtuml.serialize_instances(m)
     self.assertFalse(s)
     
     m = ooaofooa.empty_model(load_globals=True)
     s = xtuml.serialize_instances(m)
     self.assertTrue(s)
     
     ooaofooa.delete_globals(m)
     s = xtuml.serialize_instances(m)
     self.assertFalse(s)
Ejemplo n.º 2
0
    def test_remove_globals(self):
        m = ooaofooa.empty_model(load_globals=False)
        s = xtuml.serialize_instances(m)
        self.assertFalse(s)

        m = ooaofooa.empty_model(load_globals=True)
        s = xtuml.serialize_instances(m)
        self.assertTrue(s)

        ooaofooa.delete_globals(m)
        s = xtuml.serialize_instances(m)
        self.assertFalse(s)
Ejemplo n.º 3
0
    def test_serialize_default_values(self):
        schema = '''
            CREATE TABLE X (BOOLEAN BOOLEAN,
                            INTEGER INTEGER,
                            REAL REAL,
                            STRING STRING,
                            UNIQUE_ID UNIQUE_ID);
        '''
        
        loader = xtuml.ModelLoader()
        loader.input(schema)

        id_generator = xtuml.IntegerGenerator()
        m = loader.build_metamodel(id_generator)
        m.new('X')
        
        s = xtuml.serialize_instances(m)
  
        loader = xtuml.ModelLoader()
        loader.input(schema)
        loader.input(s)

        id_generator = xtuml.IntegerGenerator()
        m = loader.build_metamodel(id_generator)
        x = m.select_any('X')
        self.assertEqual(x.BOOLEAN, False)
        self.assertEqual(x.INTEGER, 0)
        self.assertEqual(x.REAL, 0.0)
        self.assertEqual(x.UNIQUE_ID, 1)
Ejemplo n.º 4
0
 def test_serialize(self):
     schema = '''
         CREATE TABLE X (BOOLEAN BOOLEAN,
                         INTEGER INTEGER,
                         REAL REAL,
                         STRING STRING,
                         UNIQUE_ID UNIQUE_ID);
     '''
     
     loader = xtuml.ModelLoader()
     loader.input(schema)
     
     m = loader.build_metamodel()
     m.new('X', BOOLEAN=True,
                INTEGER=1,
                REAL=-5.5,
                UNIQUE_ID=1)
     
     s = xtuml.serialize_instances(m)
     
     loader = xtuml.ModelLoader()
     loader.input(schema)
     loader.input(s)
     
     m = loader.build_metamodel()
     x = m.select_any('X')
     self.assertEqual(x.BOOLEAN, True)
     self.assertEqual(x.INTEGER, 1)
     self.assertEqual(x.REAL, -5.5)
     self.assertEqual(x.UNIQUE_ID, 1)
     
     self.assertIsInstance(x.BOOLEAN, bool)
     self.assertIsInstance(x.INTEGER, int)
     self.assertIsInstance(x.REAL, float)
Ejemplo n.º 5
0
    def test_serialize_default_values(self):
        schema = '''
            CREATE TABLE X (BOOLEAN BOOLEAN,
                            INTEGER INTEGER,
                            REAL REAL,
                            STRING STRING,
                            UNIQUE_ID UNIQUE_ID);
        '''

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

        id_generator = xtuml.IntegerGenerator()
        m = loader.build_metamodel(id_generator)
        m.new('X')

        s = xtuml.serialize_instances(m)

        loader = xtuml.ModelLoader()
        loader.input(schema)
        loader.input(s)

        id_generator = xtuml.IntegerGenerator()
        m = loader.build_metamodel(id_generator)
        x = m.select_any('X')
        self.assertEqual(x.BOOLEAN, False)
        self.assertEqual(x.INTEGER, 0)
        self.assertEqual(x.REAL, 0.0)
        self.assertEqual(x.UNIQUE_ID, 1)
Ejemplo n.º 6
0
    def test_serialize(self):
        schema = '''
            CREATE TABLE X (BOOLEAN BOOLEAN,
                            INTEGER INTEGER,
                            REAL REAL,
                            STRING STRING,
                            UNIQUE_ID UNIQUE_ID);
        '''

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

        m = loader.build_metamodel()
        m.new('X', BOOLEAN=True, INTEGER=1, REAL=-5.5, UNIQUE_ID=1)

        s = xtuml.serialize_instances(m)

        loader = xtuml.ModelLoader()
        loader.input(schema)
        loader.input(s)

        m = loader.build_metamodel()
        x = m.select_any('X')
        self.assertEqual(x.BOOLEAN, True)
        self.assertEqual(x.INTEGER, 1)
        self.assertEqual(x.REAL, -5.5)
        self.assertEqual(x.UNIQUE_ID, 1)

        self.assertIsInstance(x.BOOLEAN, bool)
        self.assertIsInstance(x.INTEGER, int)
        self.assertIsInstance(x.REAL, float)
Ejemplo n.º 7
0
 def test_serialize_attribute_named_self(self):
     schema = '''
         CREATE TABLE X (self UNIQUE_ID);
     '''
     
     loader = xtuml.ModelLoader()
     loader.input(schema)
     
     m = loader.build_metamodel()
     m.new('X', 1)
     
     s = xtuml.serialize_instances(m)
     
     loader = xtuml.ModelLoader()
     loader.input(schema)
     loader.input(s)
     
     m = loader.build_metamodel()
     x = m.select_any('X')
     self.assertEqual(x.self, 1)
Ejemplo n.º 8
0
    def test_serialize_attribute_named_self(self):
        schema = '''
            CREATE TABLE X (self UNIQUE_ID);
        '''

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

        m = loader.build_metamodel()
        m.new('X', 1)

        s = xtuml.serialize_instances(m)

        loader = xtuml.ModelLoader()
        loader.input(schema)
        loader.input(s)

        m = loader.build_metamodel()
        x = m.select_any('X')
        self.assertEqual(x.self, 1)
Ejemplo n.º 9
0
    def test_persist_default_values(self):
        schema = '''
            CREATE TABLE X (BOOLEAN BOOLEAN,
                            INTEGER INTEGER,
                            REAL REAL,
                            STRING STRING,
                            UNIQUE_ID UNIQUE_ID);
        '''
        
        loader = xtuml.ModelLoader()
        loader.input(schema)
        
        id_generator = xtuml.IntegerGenerator()
        m = loader.build_metamodel(id_generator)
        m.new('X')
        
        s = xtuml.serialize_instances(m)
        
        (_, filename) = tempfile.mkstemp()
        try:
            xtuml.persist_instances(m, filename)
            with open(filename) as f:
                self.assertEqual(s, f.read())
        finally:
            atexit.register(os.remove, filename)
        
        loader = xtuml.ModelLoader()
        loader.input(schema)
        loader.input(s)

        id_generator = xtuml.IntegerGenerator()
        m = loader.build_metamodel(id_generator)
        x = m.select_any('X')
        self.assertEqual(x.BOOLEAN, False)
        self.assertEqual(x.INTEGER, 0)
        self.assertEqual(x.REAL, 0.0)
        self.assertEqual(x.UNIQUE_ID, 1)
Ejemplo n.º 10
0
    def test_persist_default_values(self):
        schema = '''
            CREATE TABLE X (BOOLEAN BOOLEAN,
                            INTEGER INTEGER,
                            REAL REAL,
                            STRING STRING,
                            UNIQUE_ID UNIQUE_ID);
        '''

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

        id_generator = xtuml.IntegerGenerator()
        m = loader.build_metamodel(id_generator)
        m.new('X')

        s = xtuml.serialize_instances(m)

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

        loader = xtuml.ModelLoader()
        loader.input(schema)
        loader.input(s)

        id_generator = xtuml.IntegerGenerator()
        m = loader.build_metamodel(id_generator)
        x = m.select_any('X')
        self.assertEqual(x.BOOLEAN, False)
        self.assertEqual(x.INTEGER, 0)
        self.assertEqual(x.REAL, 0.0)
        self.assertEqual(x.UNIQUE_ID, 1)
Ejemplo n.º 11
0
#
# Create a bridge operation (My_Bridge_Operation: boolean)
#
s_dt = m.select_one('S_DT', where(Name='boolean'))
s_brg = m.new('S_BRG', Name='My_Bridge_Operation')
relate(s_brg, s_ee, 19)
relate(s_brg, s_dt, 20)

#
# Create a bridge parameter (My_Parameter: string)
#
s_dt = m.select_one('S_DT', where(Name='string'))
s_bparm = m.new('S_BPARM', Name='My_Parameter')
relate(s_bparm, s_brg, 21)
relate(s_bparm, s_dt, 22)

print('-- root-types-contained: Package_c')
print('-- generics')
print('-- BP 7.1 content: StreamData syschar: 3 persistence-version: 7.1.6')
print(xtuml.serialize_instances(m))
print('')
print('')
print(
    '-- Copy the SQL statements above, and paste them into the BridgePoint editor'
)
print(
    '-- with a project selected in the project explorer. NOTE: do not remove the'
)
print('-- first few comments.')
Ejemplo n.º 12
0
pe_pe = m.new("PE_PE", Visibility=True, type=5)
relate(s_ee, pe_pe, 8001)
relate(pe_pe, ep_pkg, 8000)

#
# Create a bridge operation (My_Bridge_Operation: boolean)
#
s_dt = m.select_one("S_DT", where(Name="boolean"))
s_brg = m.new("S_BRG", Name="My_Bridge_Operation")
relate(s_brg, s_ee, 19)
relate(s_brg, s_dt, 20)

#
# Create a bridge parameter (My_Parameter: string)
#
s_dt = m.select_one("S_DT", where(Name="string"))
s_bparm = m.new("S_BPARM", Name="My_Parameter")
relate(s_bparm, s_brg, 21)
relate(s_bparm, s_dt, 22)


print("-- root-types-contained: Package_c")
print("-- generics")
print("-- BP 7.1 content: StreamData syschar: 3 persistence-version: 7.1.6")
print(xtuml.serialize_instances(m))
print("")
print("")
print("-- Copy the SQL statements above, and paste them into the BridgePoint editor")
print("-- with a project selected in the project explorer. NOTE: do not remove the")
print("-- first few comments.")
def main():
    parser = optparse.OptionParser(usage="%prog [options] <model_path> [another_model_path...]",
                                   formatter=optparse.TitledHelpFormatter())
                                   
    parser.set_description(__doc__.strip())
    
    parser.add_option("-o", "--output", dest='output', metavar="PATH",
                      help="save sql model instances to PATH",
                      action="store", default='/dev/stdout')
    
    parser.add_option("-v", "--verbosity", dest='verbosity', action="count",
                      help="increase debug logging level", default=2)
    
    (opts, args) = parser.parse_args()
    if len(args) == 0 or None in [opts.output]:
        parser.print_help()
        sys.exit(1)

    levels = {
              0: logging.ERROR,
              1: logging.WARNING,
              2: logging.INFO,
              3: logging.DEBUG,
    }
    logging.basicConfig(level=levels.get(opts.verbosity, logging.DEBUG))
    
    m1 = bridgepoint.load_metamodel(args, load_globals=True)
    m2 = ooaofooa.empty_model()
    
    dt_boolean = m2.select_any('S_DT', where(Name='boolean'))
    dt_integer = m2.select_any('S_DT', where(Name='integer'))
    dt_real = m2.select_any('S_DT', where(Name='real'))
    dt_string = m2.select_any('S_DT', where(Name='string'))
    dt_unique_id = m2.select_any('S_DT', where(Name='unique_id'))
    dt_void = m2.select_any('S_DT', where(Name='void'))
    
    pe_pe = m2.new('PE_PE', Visibility=True, type=7)
    ep_pkg = m2.new('EP_PKG', Name='SQL_Instance_Stream_Provider')
    relate(pe_pe, ep_pkg, 8001)
    
    s_sync = mk_function(ep_pkg, Name='SQL_Instance_Stream_Connect',
                         Action_Semantics_internal=gen_connect(m1))
    mk_parameters(s_sync, from_id=dt_unique_id, from_key_letter=dt_string,
                  to_id=dt_unique_id, to_key_letter=dt_string, rel_id=dt_string)
    
    s_sync = mk_function(ep_pkg, Name='SQL_Instance_Stream_Connect_Using',
                         Action_Semantics_internal=gen_connect_using(m1))
    mk_parameters(s_sync, from_id=dt_unique_id, from_key_letter=dt_string,
                  to_id=dt_unique_id, to_key_letter=dt_string, 
                  using_id=dt_unique_id, rel_id=dt_string)
    
    s_sync = mk_function(ep_pkg, Name='SQL_Instance_Stream_New',
                         Action_Semantics_internal=gen_new(m1))
    mk_parameters(s_sync, key_letter=dt_string)
    unrelate(s_sync, dt_void, 25)
    relate(s_sync, dt_unique_id, 25)
    
    s_sync = mk_function(ep_pkg, Name='SQL_Instance_Stream_Set_Boolean',
                         Action_Semantics_internal=gen_set_boolean(m1))
    mk_parameters(s_sync, key_letter=dt_string, instance_id=dt_unique_id,
                  name=dt_string, value=dt_boolean)
    
    s_sync = mk_function(ep_pkg, Name='SQL_Instance_Stream_Set_Integer',
                         Action_Semantics_internal=gen_set_integer(m1))
    mk_parameters(s_sync, key_letter=dt_string, instance_id=dt_unique_id,
                  name=dt_string, value=dt_integer)
    
    s_sync = mk_function(ep_pkg, Name='SQL_Instance_Stream_Set_Real',
                         Action_Semantics_internal=gen_set_real(m1))
    mk_parameters(s_sync, key_letter=dt_string, instance_id=dt_unique_id,
                  name=dt_string, value=dt_real)
    
    s_sync = mk_function(ep_pkg, Name='SQL_Instance_Stream_Set_String',
                         Action_Semantics_internal=gen_set_string(m1))
    mk_parameters(s_sync, key_letter=dt_string, instance_id=dt_unique_id,
                  name=dt_string, value=dt_string)
    
    s_sync = mk_function(ep_pkg, Name='SQL_Instance_Stream_Set_Unique_Id',
                         Action_Semantics_internal=gen_set_unique_id(m1))
    mk_parameters(s_sync, key_letter=dt_string, instance_id=dt_unique_id,
                  name=dt_string, value=dt_unique_id)
    
    ooaofooa.delete_globals(m2)
    
    with open(opts.output, 'w') as f:
        f.write('-- root-types-contained: Package_c\n')
        f.write('-- generics\n')
        f.write('-- BP 7.1 content: StreamData syschar: 3 persistence-version: 7.1.6\n')
        f.write(xtuml.serialize_instances(m2))