def setup(self): # test will be skipped if unavailable import MySQLdb createTable = """\ CREATE TABLE test.sqlsequence_test (primary_id INTEGER PRIMARY KEY AUTO_INCREMENT, sequence TEXT) """ try: self.db = sqlgraph.SQLTable('test.sqlsequence_test', dropIfExists=True, createTable=createTable, attrAlias=dict(seq='sequence')) except MySQLdb.MySQLError: tempcurs = sqlgraph.getNameCursor()[1] try: # hmm, maybe need to create the test database? tempcurs.execute('create database if not exists test') self.db = sqlgraph.SQLTable('test.sqlsequence_test', dropIfExists=True, createTable=createTable, attrAlias=dict(seq='sequence')) except MySQLdb.MySQLError: # no server, database or privileges? print """\ The MySQL 'test' database doesn't exist and/or can't be created or accessed on this account. This test will be skipped. """ raise ImportError # skip tests. self.db.cursor.execute("""\ INSERT INTO test.sqlsequence_test (sequence) VALUES ('CACCCTGCCCCATCTCCCCAGCCTGGCCCCTCGTGTCTCAGAACCCTCGGGGGGAGGCACAGAAGCCTTCGGGG') """) self.db.cursor.execute("""\ INSERT INTO test.sqlsequence_test (sequence) VALUES ('GAAAGAAAGAAAGAAAGAAAGAAAGAGAGAGAGAGAGACAGAAG') """) class DNASeqRow(seqdb.DNASQLSequence): def __len__(self): # just speed optimization return self._select('length(sequence)') # SQL SELECT expression self.db.objclass(DNASeqRow) # force the table object to return DNASeqRow objects self.row1 = self.db[1] self.row2 = self.db[2]
def setup(self): from pygr import sqlgraph import MySQLdb # test will be skipped if unavailable createOpts = dict(source_id='int', target_id='int', edge_id='int') try: self.datagraph = sqlgraph.SQLGraph('test.dumbo_foo_test', dropIfExists=True, createTable=createOpts) except MySQLdb.MySQLError: tempcurs = sqlgraph.getNameCursor()[1] try: # hmm, maybe need to create the test database tempcurs.execute('create database if not exists test') self.datagraph = sqlgraph.SQLGraph('test.dumbo_foo_test', dropIfExists=True, createTable=createOpts) except MySQLdb.MySQLError: # no server, database or privileges? print """The MySQL 'test' database doesn't exist and/or can't be created or accessed on this account. This test will be skipped """ raise ImportError # skip tests.
def setup(self): # test will be skipped if unavailable import MySQLdb createTable = """\ CREATE TABLE test.sqltable_test (primary_id INTEGER PRIMARY KEY AUTO_INCREMENT, seq_id TEXT, start INTEGER, stop INTEGER) """ try: self.db = SQLTable('test.sqltable_test', dropIfExists=True, createTable=createTable) except MySQLdb.MySQLError: tempcurs = getNameCursor()[1] try: # hmm, maybe need to create the test database? tempcurs.execute('create database if not exists test') self.db = SQLTable('test.sqltable_test', dropIfExists=True, createTable=createTable) except MySQLdb.MySQLError: # no server, database or privileges? print """\ The MySQL 'test' database doesn't exist and/or can't be created or accessed on this account. This test will be skipped. """ raise ImportError # skip tests. self.db.cursor.execute("""\ INSERT INTO test.sqltable_test (seq_id, start, stop) VALUES ('seq1', 0, 10) """) self.db.cursor.execute("""\ INSERT INTO test.sqltable_test (seq_id, start, stop) VALUES ('seq2', 5, 15) """) self.sourceDB = SQLTable('test.sqltable_join1', dropIfExists=True, createTable="""\ CREATE TABLE test.sqltable_join1 (my_id INTEGER PRIMARY KEY, other_id VARCHAR(16)) """) self.targetDB = SQLTable('test.sqltable_join2', dropIfExists=True, createTable="""\ CREATE TABLE test.sqltable_join2 (third_id INTEGER PRIMARY KEY, other_id VARCHAR(16)) """) self.db.cursor.execute("""\ INSERT INTO test.sqltable_join1 VALUES (2,'seq2') """) self.db.cursor.execute("""\ INSERT INTO test.sqltable_join1 VALUES (3,'seq3') """) self.db.cursor.execute("""\ INSERT INTO test.sqltable_join1 VALUES (4,'seq4') """) self.db.cursor.execute("""\ INSERT INTO test.sqltable_join2 VALUES (7, 'seq2') """) self.db.cursor.execute("""\ INSERT INTO test.sqltable_join2 VALUES (99, 'seq3') """) self.db.cursor.execute("""\ INSERT INTO test.sqltable_join2 VALUES (6, 'seq4') """) self.db.cursor.execute("""\ INSERT INTO test.sqltable_join2 VALUES (8, 'seq4') """)
suites = map(loader, tests) return unittest.TestSuite(suites) def mysql_enabled(): """ Detects whether mysql is functional on the current system """ try: import MySQLdb except ImportError, exc: msg = 'MySQLdb error: %s' % exc warn(msg) return False try: from pygr import sqlgraph tempcurs = sqlgraph.getNameCursor()[1] # disable some MySQL specific spurious warnings, current scope only warnings.simplefilter("ignore") tempcurs.execute('create database if not exists test') except Exception, exc: msg = 'cannot operate on MySql database: %s' % exc warn(msg) return False return True def sqlite_enabled(): """ Detects whether sqlite3 is functional on the current system """