Esempio n. 1
0
class SQLTable_Setup(unittest.TestCase):
    tableClass = SQLTable
    def __init__(self, *args, **kwargs):
        unittest.TestCase.__init__(self, *args, **kwargs)
        self.serverInfo = DBServerInfo() # share conn for all tests
    def setUp(self):
        try:
            self.load_data(writeable=self.writeable)
        except ImportError:
            raise SkipTest('missing MySQLdb module?')
    def load_data(self, tableName='test.sqltable_test', writeable=False):
        'create 3 tables and load 9 rows for our tests'
        self.tableName = tableName
        self.joinTable1 = joinTable1 = tableName + '1'
        self.joinTable2 = joinTable2 = tableName + '2'
        createTable = """\
        CREATE TABLE %s (primary_id INTEGER PRIMARY KEY %%(AUTO_INCREMENT)s, seq_id TEXT, start INTEGER, stop INTEGER)
        """ % tableName
        self.db = self.tableClass(tableName, dropIfExists=True,
                                  serverInfo=self.serverInfo,
                                  createTable=createTable,
                                  writeable=writeable)
        self.sourceDB = self.tableClass(joinTable1, serverInfo=self.serverInfo,
                                        dropIfExists=True, createTable="""\
        CREATE TABLE %s (my_id INTEGER PRIMARY KEY,
              other_id VARCHAR(16))
        """ % joinTable1)
        self.targetDB = self.tableClass(joinTable2, serverInfo=self.serverInfo,
                                        dropIfExists=True, createTable="""\
        CREATE TABLE %s (third_id INTEGER PRIMARY KEY,
              other_id VARCHAR(16))
        """ % joinTable2)
        sql = """
            INSERT INTO %s (seq_id, start, stop) VALUES ('seq1', 0, 10)
            INSERT INTO %s (seq_id, start, stop) VALUES ('seq2', 5, 15)
            INSERT INTO %s VALUES (2,'seq2')
            INSERT INTO %s VALUES (3,'seq3')
            INSERT INTO %s VALUES (4,'seq4')
            INSERT INTO %s VALUES (7, 'seq2')
            INSERT INTO %s VALUES (99, 'seq3')
            INSERT INTO %s VALUES (6, 'seq4')
            INSERT INTO %s VALUES (8, 'seq4')
        """ % tuple(([tableName]*2) + ([joinTable1]*3) + ([joinTable2]*4))
        for line in sql.strip().splitlines(): # insert our test data
            self.db.cursor.execute(line.strip())
    def tearDown(self):
        self.db.cursor.execute('drop table if exists %s' % self.tableName)
        self.db.cursor.execute('drop table if exists %s' % self.joinTable1)
        self.db.cursor.execute('drop table if exists %s' % self.joinTable2)
        self.serverInfo.close()
Esempio n. 2
0
    def setUp(self):
        # test will be skipped if mysql module or ensembldb server unavailable

        logger.debug('accessing ensembldb.ensembl.org')
        conn = DBServerInfo(host='ensembldb.ensembl.org',
                            user='******',
                            passwd='')
        try:
            translationDB = \
                    SQLTableCatcher('homo_sapiens_core_47_36i.translation',
                                    serverInfo=conn)
            translationDB.catchIter = True  # should not iter in this test!
            exonDB = SQLTable('homo_sapiens_core_47_36i.exon', serverInfo=conn)
        except ImportError, e:
            raise SkipTest(e)
Esempio n. 3
0
 def __init__(self, *args, **kwargs):
     unittest.TestCase.__init__(self, *args, **kwargs)
     self.serverInfo = DBServerInfo() # share conn for all tests
class SQLTable_Setup(unittest.TestCase):
    tableClass = SQLTableCatcher
    serverArgs = {}
    loadArgs = {}

    def __init__(self, *args, **kwargs):
        unittest.TestCase.__init__(self, *args, **kwargs)
        # share conn for all tests
        self.serverInfo = DBServerInfo(** self.serverArgs)

    def setUp(self):
        if not testutil.mysql_enabled():
            raise SkipTest("no MySQL installed")
        self.load_data(writeable=self.writeable, ** self.loadArgs)

    def load_data(self, tableName='test.sqltable_test', writeable=False,
                  dbargs={}, sourceDBargs={}, targetDBargs={}):
        'create 3 tables and load 9 rows for our tests'
        self.tableName = tableName
        self.joinTable1 = joinTable1 = tableName + '1'
        self.joinTable2 = joinTable2 = tableName + '2'
        createTable = 'CREATE TABLE %s (primary_id INTEGER PRIMARY KEY \
                %%(AUTO_INCREMENT)s, seq_id TEXT, start INTEGER, \
                stop INTEGER)' % tableName
        self.db = self.tableClass(tableName, dropIfExists=True,
                                  serverInfo=self.serverInfo,
                                  createTable=createTable,
                                  writeable=writeable,
                                  attrAlias=dict(sequence_id='seq_id',
                                                 minStop="min(stop)"),
                                  **dbargs)
        self.sourceDB = self.tableClass(joinTable1, serverInfo=self.serverInfo,
                                        dropIfExists=True, createTable="""\
        CREATE TABLE %s (my_id INTEGER PRIMARY KEY,
              other_id VARCHAR(16))
        """ % joinTable1, **sourceDBargs)
        self.targetDB = self.tableClass(joinTable2, serverInfo=self.serverInfo,
                                        dropIfExists=True, createTable="""\
        CREATE TABLE %s (third_id INTEGER PRIMARY KEY,
              other_id VARCHAR(16))
        """ % joinTable2, **targetDBargs)
        sql = """
            INSERT INTO %s (seq_id, start, stop) VALUES ('seq1', 0, 10)
            INSERT INTO %s (seq_id, start, stop) VALUES ('seq2', 5, 15)
            INSERT INTO %s VALUES (2,'seq2')
            INSERT INTO %s VALUES (3,'seq3')
            INSERT INTO %s VALUES (4,'seq4')
            INSERT INTO %s VALUES (7, 'seq2')
            INSERT INTO %s VALUES (99, 'seq3')
            INSERT INTO %s VALUES (6, 'seq4')
            INSERT INTO %s VALUES (8, 'seq4')
        """ % tuple(([tableName]*2) + ([joinTable1]*3) + ([joinTable2]*4))
        for line in sql.strip().splitlines(): # insert our test data
            self.db.cursor.execute(line.strip())

        # Another table, for the "ORDER BY" test
        self.orderTable = tableName + '_orderBy'
        self.db.cursor.execute('DROP TABLE IF EXISTS %s' % self.orderTable)
        self.db.cursor.execute('CREATE TABLE %s (id INTEGER PRIMARY KEY, \
                               number INTEGER, letter VARCHAR(1))'
                               % self.orderTable)
        for row in range(0, 10):
            self.db.cursor.execute('INSERT INTO %s VALUES (%d, %d, \'%s\')' %
                                   (self.orderTable, row,
                                    random.randint(0, 99),
                                    string.lowercase[random.randint(0,
                                                          len(string.lowercase)
                                                                    - 1)]))

    def tearDown(self):
        self.db.cursor.execute('drop table if exists %s' % self.tableName)
        self.db.cursor.execute('drop table if exists %s' % self.joinTable1)
        self.db.cursor.execute('drop table if exists %s' % self.joinTable2)
        self.db.cursor.execute('drop table if exists %s' % self.orderTable)
        self.serverInfo.close()
Esempio n. 5
0
 def __init__(self, *args, **kwargs):
     unittest.TestCase.__init__(self, *args, **kwargs)
     # share conn for all tests
     self.serverInfo = DBServerInfo(**self.serverArgs)
Esempio n. 6
0
class SQLTable_Setup(unittest.TestCase):
    tableClass = SQLTableCatcher
    serverArgs = {}
    loadArgs = {}

    def __init__(self, *args, **kwargs):
        unittest.TestCase.__init__(self, *args, **kwargs)
        # share conn for all tests
        self.serverInfo = DBServerInfo(**self.serverArgs)

    def setUp(self):
        if not testutil.mysql_enabled():
            raise SkipTest("no MySQL installed")
        self.load_data(writeable=self.writeable, **self.loadArgs)

    def load_data(self,
                  tableName='test.sqltable_test',
                  writeable=False,
                  dbargs={},
                  sourceDBargs={},
                  targetDBargs={}):
        'create 3 tables and load 9 rows for our tests'
        self.tableName = tableName
        self.joinTable1 = joinTable1 = tableName + '1'
        self.joinTable2 = joinTable2 = tableName + '2'
        createTable = 'CREATE TABLE %s (primary_id INTEGER PRIMARY KEY \
                %%(AUTO_INCREMENT)s, seq_id TEXT, start INTEGER, \
                stop INTEGER)' % tableName
        self.db = self.tableClass(tableName,
                                  dropIfExists=True,
                                  serverInfo=self.serverInfo,
                                  createTable=createTable,
                                  writeable=writeable,
                                  attrAlias=dict(sequence_id='seq_id',
                                                 minStop="min(stop)"),
                                  **dbargs)
        self.sourceDB = self.tableClass(joinTable1,
                                        serverInfo=self.serverInfo,
                                        dropIfExists=True,
                                        createTable="""\
        CREATE TABLE %s (my_id INTEGER PRIMARY KEY,
              other_id VARCHAR(16))
        """ % joinTable1,
                                        **sourceDBargs)
        self.targetDB = self.tableClass(joinTable2,
                                        serverInfo=self.serverInfo,
                                        dropIfExists=True,
                                        createTable="""\
        CREATE TABLE %s (third_id INTEGER PRIMARY KEY,
              other_id VARCHAR(16))
        """ % joinTable2,
                                        **targetDBargs)
        sql = """
            INSERT INTO %s (seq_id, start, stop) VALUES ('seq1', 0, 10)
            INSERT INTO %s (seq_id, start, stop) VALUES ('seq2', 5, 15)
            INSERT INTO %s VALUES (2,'seq2')
            INSERT INTO %s VALUES (3,'seq3')
            INSERT INTO %s VALUES (4,'seq4')
            INSERT INTO %s VALUES (7, 'seq2')
            INSERT INTO %s VALUES (99, 'seq3')
            INSERT INTO %s VALUES (6, 'seq4')
            INSERT INTO %s VALUES (8, 'seq4')
        """ % tuple(([tableName] * 2) + ([joinTable1] * 3) +
                    ([joinTable2] * 4))
        for line in sql.strip().splitlines():  # insert our test data
            self.db.cursor.execute(line.strip())

        # Another table, for the "ORDER BY" test
        self.orderTable = tableName + '_orderBy'
        self.db.cursor.execute('DROP TABLE IF EXISTS %s' % self.orderTable)
        self.db.cursor.execute('CREATE TABLE %s (id INTEGER PRIMARY KEY, \
                               number INTEGER, letter VARCHAR(1))' %
                               self.orderTable)
        for row in range(0, 10):
            self.db.cursor.execute(
                'INSERT INTO %s VALUES (%d, %d, \'%s\')' %
                (self.orderTable, row, random.randint(0, 99),
                 string.lowercase[random.randint(0,
                                                 len(string.lowercase) - 1)]))

    def tearDown(self):
        self.db.cursor.execute('drop table if exists %s' % self.tableName)
        self.db.cursor.execute('drop table if exists %s' % self.joinTable1)
        self.db.cursor.execute('drop table if exists %s' % self.joinTable2)
        self.db.cursor.execute('drop table if exists %s' % self.orderTable)
        self.serverInfo.close()