Back to index

python-biopython  1.60
Classes | Functions | Variables
test_BioSQL Namespace Reference

Classes

class  ReadTest
class  SeqInterfaceTest
class  LoaderTest
class  DupLoadTest
class  ClosedLoopTest
class  TransferTest
class  InDepthLoadTest

Functions

def _do_db_create
def create_database
def load_database

Variables

string message = "Check settings in Tests/setup_BioSQL.py "
tuple server = BioSeqDatabase.open_database(driver = DBDRIVER, db = TESTDB)
tuple runner = unittest.TextTestRunner(verbosity = 2)

Function Documentation

def test_BioSQL._do_db_create ( ) [private]
Do the actual work of database creation. Relevant for MySQL and PostgreSQL

Definition at line 51 of file test_BioSQL.py.

00051 
00052 def _do_db_create():
00053     """Do the actual work of database creation. Relevant for MySQL and PostgreSQL
00054     """
00055     # first open a connection to create the database
00056     server = BioSeqDatabase.open_database(driver = DBDRIVER,
00057                                           user = DBUSER, passwd = DBPASSWD,
00058                                           host = DBHOST)
00059 
00060     if DBDRIVER == "pgdb":
00061         # The pgdb postgres driver does not support autocommit, so here we 
00062         # commit the current transaction so that 'drop database' query will
00063         # be outside a transaction block
00064         server.adaptor.cursor.execute("COMMIT")
00065     else:
00066         # Auto-commit: postgresql cannot drop database in a transaction
00067         try:
00068             server.adaptor.autocommit()
00069         except AttributeError:
00070             pass
00071 
00072     # drop anything in the database
00073     try:
00074         # with Postgres, can get errors about database still being used and
00075         # not able to be dropped. Wait briefly to be sure previous tests are
00076         # done with it.
00077         import time
00078         time.sleep(1)
00079 
00080         sql = r"DROP DATABASE " + TESTDB
00081         server.adaptor.cursor.execute(sql, ())
00082     except (server.module.OperationalError,
00083             server.module.DatabaseError), e: # the database doesn't exist
00084         pass
00085     except (server.module.IntegrityError,
00086             server.module.ProgrammingError), e: # ditto--perhaps
00087         if str(e).find('database "%s" does not exist' % TESTDB) == -1:
00088             raise
00089     # create a new database
00090     sql = r"CREATE DATABASE " + TESTDB
00091     server.adaptor.execute(sql, ())
00092     server.close()

Here is the call graph for this function:

Here is the caller graph for this function:

Delete any existing BioSQL test database, then (re)create an empty BioSQL database.

Definition at line 93 of file test_BioSQL.py.

00093 
00094 def create_database():
00095     """Delete any existing BioSQL test database, then (re)create an empty BioSQL database."""
00096     if DBDRIVER in ["sqlite3"]: 
00097         if os.path.exists(TESTDB):
00098             os.remove(TESTDB)
00099     else:
00100         _do_db_create()
00101 
00102     # now open a connection to load the database
00103     server = BioSeqDatabase.open_database(driver = DBDRIVER,
00104                                           user = DBUSER, passwd = DBPASSWD,
00105                                           host = DBHOST, db = TESTDB)
00106     server.load_database_sql(SQL_FILE)
00107     server.commit()
00108     server.close()

Here is the call graph for this function:

Here is the caller graph for this function:

def test_BioSQL.load_database (   gb_handle)
Load a GenBank file into a new BioSQL database.

This is useful for running tests against a newly created database.

Definition at line 109 of file test_BioSQL.py.

00109 
00110 def load_database(gb_handle):
00111     """Load a GenBank file into a new BioSQL database.
00112     
00113     This is useful for running tests against a newly created database.
00114     """
00115 
00116     create_database()
00117     # now open a connection to load the database
00118     db_name = "biosql-test"
00119     server = BioSeqDatabase.open_database(driver = DBDRIVER,
00120                                           user = DBUSER, passwd = DBPASSWD,
00121                                           host = DBHOST, db = TESTDB)
00122     db = server.new_database(db_name)
00123     
00124     # get the GenBank file we are going to put into it
00125     iterator = SeqIO.parse(gb_handle, "gb")
00126     # finally put it in the database
00127     count = db.load(iterator)
00128     server.commit()
00129     server.close()
00130     return count

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

string test_BioSQL.message = "Check settings in Tests/setup_BioSQL.py "

Definition at line 31 of file test_BioSQL.py.

tuple test_BioSQL.runner = unittest.TextTestRunner(verbosity = 2)

Definition at line 709 of file test_BioSQL.py.

tuple test_BioSQL.server = BioSeqDatabase.open_database(driver = DBDRIVER, db = TESTDB)

Definition at line 37 of file test_BioSQL.py.